/*
 *  BY DESIGNISDEAD
 *  THIS IS NOT WORK OF Live Nation (Music) UK
 *
 *  edited by Michal Gondar @ Live Nation (Music) UK
 */


/*--- setting global variables --------------------------------------------------------------------------------*/
var animationSpeed = 1; //for flash and javascript delays and animations
var contentHidden = false; //to know if content is hidden or not, while changing flash media


// Delay Plugin for jQuery
// - http://www.evanbot.com
// - © 2008 Evan Byrne

jQuery.fn.delay = function(time,func){
	return this.each(function(){
		setTimeout(func,time);
	});
};


/*--- listeners -----------------------------------------------------------------------------------------------*/

var jsReady = false;
var lang = "nl";
var pID = "";
var aID = "";

/*start javascript on dom ready*/
$(document).ready(function() 
{
  jsReady = true;
  lang = $("#language").html();
  pID = $("#pID").html();
  aID = $("#aID").html();
	
	/*loading all flashes and resize to windowsize*/
	loadFlash();
	resizeFlashes();
	
	/*dev listeners*/
	$('#gelleryButton').click(function(){
	    if( contentHidden == false ) {
		    hideContent('media');
		} else {
		    showContent('media');
		}
		return false;
	});


	/*dev listeners*/
	$('#logoBG ul li a.gallery').click(function(){
	    if( contentHidden == false ) {
		    hideContent('media');
		} else {
		    showContent('media');
		}
		return false;
	});


	/*javascript to fake IE6 in using posiotion fixed (scroll problem)*/
	if(jQuery.browser.msie && parseInt(jQuery.browser.version)<7){
		$(window).scroll(function(){
            $('#infiniteBGfooter').css("top", document.documentElement.clientHeight + document.documentElement.scrollTop - $('#infiniteBGfooter').height() - 0 + "px");
        });
    };

    if (pID == null) pID = "";
    if (aID == null) aID = "";

    // automatic open gallery
    if((aID != "") || (pID != "")){
        hideContent('media');
    }

});

/*window resize listener*/
$(window).resize(function(){
	
	/*resize flashes to fit windowsize*/
	resizeFlashes();
	
});



/*--- functions -----------------------------------------------------------------------------------------------*/

/*catching flash object to make interaction between flash and js possible*/
function getFlashMovieObject(movieName){
	if (window.document[movieName]){
	  return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName]) {
			return document.embeds[movieName];
		}
		else {
			return document.getElementById(movieName);
		}
	}
}

/*calling the open or close animation in the medialibrary flash*/
function animateMedia(i,m){
	try {
		var media = getFlashMovieObject('flashGallery');
		
		if(i=='start'){
			media.openAnimation(m,animationSpeed);
		}else if(i=='change'){
			media.changeAnimation(m,animationSpeed);
		}else{
			media.closeAnimation(animationSpeed);
		}
	}
	catch(err){};
}

function availableHeightFc() {
	//getting current available height for stretchable flash elements
	var footerHeight = $('#infiniteBGfooter').height();
	var windowHeight = jQuery(window).height();
	return windowHeight - footerHeight;	
}

/*resize background and media library flash to fit window*/
function resizeFlashes(){

	//getting current available height for stretchable flash elements
	var availableHeight = availableHeightFc();

	//setting the height
	if($('#flashGallery').height() > 10){
		$('#flashGallery').height(availableHeight);
	}


	/*javascript to fake IE6 in using posiotion fixed (scroll problem)*/
	if(jQuery.browser.msie && parseInt(jQuery.browser.version)<7){
	    $('#infiniteBGfooter').css("position", "absolute");
	    $('#infiniteBGfooter').css("top", "auto");
	    $('#infiniteBGfooter').css("width", document.body.clientWidth + "px");
        $('#infiniteBGfooter').css("bottom", "-1px");
	}

}

/*slide content up and show media flash*/
function hideContent(m){
	
	if (!contentHidden) { //preventing double execution
		//content now visible
		//contentHidden = true;

        // hide other opened footer boxes
        hideOthersFooterBoxes();

		//getting current available height for stretchable flash elements
		var availableHeight = availableHeightFc();

        // repairst first flash blink, when height is set to 100% by css
        resizeFlashes();


		//fixing browser differences
		if (!jQuery.browser.msie || (jQuery.browser.msie && parseInt(jQuery.browser.version) > 7)) {
			var newTop = (10 - $('#slideAllContent').height()) + 'px';
		}
		else {
			var newTop = (0 - $('#slideAllContent').height()) + 'px';
		}

		//do the animations
		$('#slideAllContent').animate({
			top: newTop
		}, 'normal', 'linear', function(){
			$('#flashGallery').height(availableHeight);
			animateMedia('start',m);
			contentHidden = true;
		});

/*

    	// show gallery in safari
		$('#flashGallery').css("top", "0");
		// show gallery
		// after slideup, hide content, because of verticval scrollbar
		$('#flashGallery').slideDown("slow", function() { resizeFlashes(); $('#infiniteBGmain').css("display", "none"); contentHidden = true; } );

        // repairs bug whn is opend submenu in footer
		resizeFlashes();

        $("#gelleryButton").addClass("selected");
*/
	}else{
		animateMedia('change',m);
	}
		
}

/*hide media flash and slide back the content*/
function showContent(s)
{
	if(contentHidden) { //preventing double execution
	
		//content now visible
		contentHidden = false;
		
		//do the animations
		animateMedia('close');

		//delayed js animation, start when media flash has finished closing
		$(this).delay((1*animationSpeed),function(){
/*
			// show content
			$('#infiniteBGmain').css("display", "block");
		    // hide gallery
			// after slideup, hide flashGallery in safari
			$('#flashGallery').slideUp("slow", function() { $('#flashGallery').css("top", "-99999em"); $('#infiniteBGmain').css("display", "block"); contentHidden = false; } );

            // repairs bug whn is opend submenu in footer
            resizeFlashes();
*/
			$('#flashGallery').height(0);
			$('#slideAllContent').animate({top: '0'},'normal','easeInOutQuad', function() { contentHidden = false; });
		});
		
        $("#gelleryButton").removeClass("selected");
	}
}

/*load all flash elements into the html using swfobject*/
function loadFlash(){
/*
alert(pID);
alert(aID);
*/
	//media library
    var flashvars = { SWF_PATH: "/_Resources/flash/", DEEP_LINKED_ALBUM: aID, DEEP_LINKED_PHOTO: pID, GALLERY_XML_PATH: "/" + lang + "/gallery/index.aspx", SEARCH_XML_PATH: "", TAG_XML_PATH: "", SEND_TO_FRIEND_URL: "/" + lang + "/feedback/gallerySendToFriend.aspx", SEARCH_ENABLED: "", TAG_CLOUD_ENABLED: "" };
	var params = {allowScriptAccess: "always", bgcolor:"#000000"};
	var attributes = {};
	swfobject.embedSWF("/_Resources/flash/container_1.swf", "flashGallery", "100%", "0", "9.0.0", "expressInstall.swf", flashvars, params, attributes);

}

/*--- js vs as -----------------------------------------------------------------------------------------------*/
function isReady() 
{
  return jsReady;
}
