// JavaScript Document
jQuery(window).bind('load resize', function(e){
	if (!$.browser.msie) {
		if (e.type === 'resize'){
			jQuery('.shadow').redrawShadow();
		} else {
			jQuery('.shadow').dropShadow({
				left:.5,
				top:.5,
				opacity: 0.8,
				blur:4
			});
		}
	}
});

jQuery(document).ready(function () {
    var winwidth = jQuery(window).width();
    winheight = jQuery(window).height();
    if (winwidth < 1024) winwidth = 1024;
	
	// Show tiny thumbnails on registration list
	$("span.regthumb").toggle(preferences.showheadshot);

	remove_ppt();
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		theme:'pp_default',
		opacity:0.8,
		deeplinking: false,
		show_title: true,
		allow_resize: true,
		overlay_gallery: false,
		social_tools: ""
	});

	// If there is an Error	show it
	if(jQuery("#error").size()) {
		//jQuery.prettyPhoto.open("#error");
	}

	jQuery("a[title]").qtip({
		position: {
			my: 'top right',  // Position my top left...
			at: 'bottom left' // at the bottom right of...
		}
	});
	jQuery("div.innerPage").corner("top");
	jQuery("div.rounded").corner();

	jQuery.PeriodicalUpdater({
	  url : '/includes/global_banner.asp',
	  minTimeout: 10000,
	  maxTimeout: 10000
	},
	function(data){
	  jQuery('#sponsor').html(data);
	});
	
    jQuery(".bgIMg img").attr('width', winwidth);

    jQuery(window).resize(function () {
        var winwidth = jQuery(window).width();
        if (winwidth >= 1024) jQuery(".bgIMg img").attr('width', winwidth);

    }); // End: jQuery(document).ready(function(){
	jQuery(".headerImg img").css("width", "100%");

	//jQuery(".headMenu").append('<li class="last"></li>').prepend('<li class="first"></li>');
	if (jQuery(".headMenu li").hasClass('active')) {
		var selected = jQuery(".headMenu li.active");
		if (selected.prev('li').hasClass('first')) {
			selected.prev('li').addClass('firstActive');
		};
		if (selected.next('li').hasClass('last')) {
			selected.next('li').addClass('lastActive');
		};
	}
	
	jQuery(".headMenu li").hover(function () {
		jQuery(this).addClass('hover').prev('li').addClass('firstActive');
		jQuery(this).next('li').addClass('lastActive');
	}, function () {
		jQuery(this).removeClass('hover');
		if (!jQuery(this).hasClass('active')) {
			jQuery(this).prev('li').removeClass('firstActive');
			jQuery(this).next('li').removeClass('lastActive');
		};
	});
	
	jQuery('#topMenu li').hover(function () {
		$(this).addClass('over')
	}, function () {
		$(this).removeClass('over');
	});
	jQuery(".showloginbox").hover(function () {
		jQuery(this).closest('.headMenu').addClass('hover');
	}, function () {
		jQuery(this).closest('.headMenu').removeClass('hover');
	});


		// Initialize Floating Menu
/*		var $scrollingDiv = $("#floatMenu");
		var lastTop = 0;
		var newTop = 0;
 */
		$(window).scroll(function(){
			newTop = $(window).scrollTop();
/*			if(lastTop<newTop) {
				$scrollingDiv.stop().animate({"marginTop": ($(window).scrollTop()) + "px"}, "slow" );
			} else {
				$scrollingDiv.stop().css("marginTop", newTop);
			}
			lastTop = newTop;
*/			
			if(newTop > 35)
				$("#floatMenu").stop().animate({'opacity':'0.2'},400);
			else
				$("#floatMenu").stop().animate({'opacity':'1'},400);			
		});

		$("#floatMenu").hover(
			function (e) {
				var scrollTop = $(window).scrollTop();
				if(scrollTop != 0){
					$("#floatMenu").stop().animate({'opacity':'1'},400);
				}
			},
			function (e) {
				var scrollTop = $(window).scrollTop();
				if(scrollTop != 0){
					$("#floatMenu").stop().animate({'opacity':'0.2'},400);
				}
			}
		);
		
/*		// Z-Index Fix for IE7
		if ( $.browser.msie  && parseInt($.browser.version.substr(0,3)) < 8 && navigator.userAgent.indexOf("Trident/4.0", 1)<0) {
			alert("This site was designed to take advantage of the latest web technologies.  Please upgrade to the latest version of Internet Explorer.");
			
			$(function() {
				var zIndexNumber = 1000;
				$('div').each(function() {
					$(this).css('zIndex', zIndexNumber);
					zIndexNumber -= 10;
				});
			});	
		}	
*/

});


jQuery(".blogs a.loadmore").live('click', function () {
    var v = jQuery(this);
    v.closest('.blogs').append('<div class="ajaxload"></div>');
    jQuery.getJSON(v.attr('href'), function (json) {
        if (json.errorno == 0) {
            v.closest('.blogs').html(json.myhtml);
        } else {
            alert(json.error);
            jQuery(".ajaxload").remove();
        }
    });
    return false;
});
jQuery(".showloginbox").live('click', function () {
    var v = jQuery(this);
    v.closest('.headMenu').slideUp('slow', function () {
        v.hide();
        jQuery(".signupbutton").hide();
        jQuery("#loginbox").show();
        jQuery("#signup").hide();
        v.closest('.headMenu').slideDown('slow').addClass('show');
    });
    return false;
});

jQuery("a.hideloginbox").live('click', function () {
    var v = jQuery(this);
    v.closest('.headMenu').slideUp('slow', function () {
        jQuery(".showloginbox").show();
        jQuery(".signupbutton").show();
        jQuery("#loginbox").hide();
        v.closest('.headMenu').slideDown('slow').removeClass('show');
    });
    return false;
});

jQuery(".eventsearch ul li span.droplist").live('click', function () {
    jQuery(this).toggleClass('over');
    jQuery(this).closest('li').find('.dropbox').slideToggle("slow");
    return false;
});

jQuery('.noztooltip').live('mouseover', function (e) {
    var t = jQuery(this);
    if (t.attr('title') !== '') {
        t.data('title', t.attr('title')).attr('title', '');
    }
    jQuery('#ntzTooltip').remove();
    jQuery('<span id="ntzTooltip"/>').html(t.data('title')).css({
        left: t.offset().left + t.width(),
        top: t.offset().top - t.height()
    }).appendTo('body');
}).live('mouseout', function () {
    jQuery('#ntzTooltip').remove();
});

jQuery("a.edit").live('click', function () {
    var v = jQuery(this);
    jQuery.facebox('<center>Loading...</center>');
    jQuery.getJSON(v.attr('href'), function (json) {
        if (json.errorno == 0) {
            jQuery.facebox(json.myhtml);
            jQuery(function () {
                loadcropjs();
            });
        } else {
            jAlert(json.error, ':: Server Response ::');
            jQuery.facebox.close();
        }
    });
    return false;
});


jQuery("#imagecrop .submit").live('click', function () {
    var t = jQuery(this);
    var handler = jQuery("#profilePhoto span");
    var options = {
        beforeSubmit: defaultload(jQuery("#imagecrop")),
        dataType: 'json',
        success: function (json) {
            if (json.errorno == 0) {
                handler.html(json.myhtml);
                jQuery("#facebox a.close").trigger('click');
            } else {
                jAlert(json.error, ':: Server Response ::');
                jQuery("#fecebox a.close").trigger('click');
            }
        },
        clearForm: true,
        resetForm: true
    };
    jQuery('#' + t.closest('form').attr('id')).ajaxSubmit(options);
    return false;
});

jQuery(".editablearea a.textedit, a.cancelform").live('click', function () {
    var v = jQuery(this);
    v.closest('.editablearea').append('<div class="ajaxloader"></div>');
    jQuery.getJSON(v.attr('href'), function (json) {
        if (json.errorno == 0) {
            v.closest('.editablearea').html(json.myhtml);
            jQuery(function () {
                additionalonload();
            });
        } else {
            jAlert(json.error, ':: Server Response ::');
            jQuery('.ajaxloader').remove();
        }
    });
    return false;
});

jQuery(".editablearea .ajaxformsubmit").live('click', function () {
    var t = jQuery(this);
    var handler = t.closest('.editablearea');
    var options = {
        beforeSubmit: defaultload(handler),
        dataType: 'json',
        success: function (json) {
            if (json.errorno == 0) {
                handler.html(json.myhtml);
            } else {
                jAlert(json.error, ':: Server Response ::');
                jQuery('.ajaxloader').remove();
            }
        },
        clearForm: true,
        resetForm: true
    };
    jQuery('#' + t.closest('form').attr('id')).ajaxSubmit(options);
    return false;
});

jQuery(".formarea ul li input.checkbox").live('click', function () {
    if (jQuery(this).is(':checked')) {
        jQuery(this).closest('li').addClass('active');
    } else {
        jQuery(this).closest('li').removeClass('active');
    }
});

jQuery("a.closebtn").live('click', function () {
    jQuery(this).closest('.msgbox').fadeOut('slow');
    return false;
});

jQuery("#eventselect").live('change', function () {
    var v = jQuery(this);
    var handler = v.closest('.module').find(".homeEventtab")
    handler.append('<div class="ajaxload"></div>');
    jAlert(v.val());
    jQuery.getJSON(v.val(), function (json) {
        if (json.errorno == 0) {
            handler.html(json.myhtml);
        } else {
            jAlert(json.error, ':: Server Response ::');
        }
    });
});

function loadcropjs() {
    jQuery('#cropbox').Jcrop({
        aspectRatio: 1
    });
}

function defaultload(id) {
    id.append('<div class="ajaxload"></div>')
}

function additionalonload() {
    jQuery(".default-usage-select").selectbox();
    jQuery('.datepicker').datepicker({
        changeMonth: true,
        changeYear: true
    });
}

function remove_ppt(){
	$(".pp_pic_holder").remove();
	$(".pp_overlay").remove();
	$(".ppt").remove();
}
