//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$j("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$j("#backgroundPopup").fadeIn("slow");
		$j("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$j("#backgroundPopup").fadeOut("slow");
		$j("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
	$j("#contactArea").html('');
}

//centering popup
function centerPopup(offset){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $j("#popupContact").height();
	var popupWidth = $j("#popupContact").width();
	
	//centering
	
	$j("#popupContact").fixedCenter();
	
	/*
	$j("#popupContact").css({
		"position": "absolute",
		"top": $j(document).scrollTop() - (popupHeight*1.5),
		"left": '50%',
		"marginLeft": (popupWidth/2)*(-1)
		//"left": windowWidth/2-popupWidth/2
	});*/
	
	$j("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


MTVN.VH1 = {};
MTVN.VH1.CycleList = new function () {
    this.index = 0;
    this.delay = 5000; //millisecond delay between cycles
    
    this.cycleThru = function () {
        var imax = $j("ul.feed-container > li").length -1;
        $j("ul.feed-container > li:eq(" + MTVN.VH1.CycleList.index + ")")
             .fadeIn("slow")
             .animate({"opacity" : "1"} ,400)
             .animate({"opacity" : "1"}, MTVN.VH1.CycleList.delay)
             .animate({"opacity" : "0"}, 400, function(){
                 $j(this).hide();
                 (MTVN.VH1.CycleList.index == imax) ? MTVN.VH1.CycleList.index=0 : MTVN.VH1.CycleList.index++;
                 MTVN.VH1.CycleList.cycleThru();
        });
    };
    
    this.initCycleThru = function () {
        $j("ul.feed-container > li").each(function(){
            $j(this).hide();
        });
        this.cycleThru();
    };
}

$j.fn.fixedCenter = function(){
	return this.each(function(){
		var element = jQuery(this), win = jQuery(window);
		centerElement();
		
		jQuery(window).bind('resize',function(){
			centerElement();
		});

		function centerElement(){
			var elementWidth, elementHeight, windowWidth, windowHeight, X2, Y2;
			elementWidth = element.outerWidth();
			elementHeight = element.outerHeight();
			windowWidth = win.width();
			windowHeight = win.height();	
			X2 = (windowWidth/2 - elementWidth/2) + "px";
			Y2 = (windowHeight/2 - elementHeight/2) + "px";
			jQuery(element).css({
				'left':X2,
				'top':Y2,
				'position':'fixed'
			});						
		} //centerElement function
	});
}

