/* 
	Star Musician of Iran 
	© 2011 www.starmusician.com  
	version 1.0          
*/


/*==========================*/
/*   General Site Scripts   */
/*==========================*/

$(document).ready(function(){
	
	// Setup Background fullscreen
	
	$theBorder=20; //border around image (change top and left values of #bg accordingly)
	$bg=$("#bg");
	$bgimg=$("#bg #bgimg");
	$preloader=$("#loading");
	$languageSelect=$("#languageSelect");
	
	/*$bgimg.jail({
		event:'load',
		timeout: 2000,
		effect: 'fadeIn',
		speed: 2000,
		callbackAfterEachImage : function(){
			FullScreenBackground($bgimg,$bg);
			$preloader.fadeOut("slow");
		}
	});
*/
	
	
	$(window).load(function() {
		FullScreenBackground($bgimg,$bg);
		$preloader.fadeOut("slow", function(){
			$languageSelect.show();
		});
	 
		$(window).resize(function() {
			FullScreenBackground($bgimg,$bg);
		});
	});
	 
	$bgimg.load(function() {
		var $this=$(this);
		FullScreenBackground($this,$bg);
		$preloader.fadeOut("fast", function(){
			$languageSelect.show();
		});
		$this.delay(200).fadeIn("slow");
	});

	
	// Main Menu functionality
	$(".megamenu").megamenu();
	
	
	// Hide or show video scroller panel 
	$("#footer-scorller-control").click(function(event){
		event.preventDefault();
		$.post("/calls/showPlaylist.cfm");
		if ( $(this).text() == '- Minimize' ) {
			$(this).text('+ Maximize');
			$("#footer-search").css('bottom','20px');
			$("#footer-scroller").hide();
		} else {
			$(this).text('- Minimize');
			$("#footer-search").css('bottom','120px');
			$("#footer-scroller").show();	
		}
	});
	
	//Search button
	$( "#btn_search" ).button({
		icons: {
			primary: "ui-icon-search"
		},
		text: false
	});
	
	// Side navigation functionality
	$( "button", "#sub-nav-close").hide();
	$( ".sub-nav").hide();
	$( ".sub-nav-ad").hide();
	
	$(".mainLink").click(function(event){
		event.preventDefault();
		var currentNavId = "#" + $(this).attr('id');
		var currentSubNavId = "#nav-" + $(this).attr('id');
		var currentLinkId = "#link-" + $(".current").attr('id') + "-bg";
		var clickedLinkId = "#link-" + $(this).attr('id') + "-bg";
		var currentAdId = currentSubNavId + "-ad";
		if( $(".content-body-left").hasClass('openNav') ) {
			if (clickedLinkId != currentLinkId)
			$( currentLinkId ).stop().animate({left:'200px'},{queue:false, duration:600, easing: 'easeOutCirc'});
			$(".current").removeClass('current');
			$(".content-body-right").fadeIn(1000);
			$(".sub-nav").fadeOut(500);
			$(".sub-nav-ad").fadeOut(500);
			$( "button", "#sub-nav-close").fadeOut(500);
			$("#content-body-wrapper", "#content-body").animate({left:'-201px'}, {queue:true, duration:1000, complete: function(){ 
					$(".player").css({ 'width' : '640px', 'height' : '360px' }).removeClass("bg_medium").addClass("bg_large");
				} });
			$(".content-body-left").removeClass('openNav');
			$(".content-body-full").removeClass('content-body-mid');

			$(".full-div").animate({width:720}, 1000);
			$(".player>img").css({'bottom' : '130px', 'left' : '280px'});
			$("div.video-wrapper").css({'padding' : '0 40px'});
			$(".player>.info").css({ 'width':'610px' });
			$("#video-panel").animate({width:600}, 1000);
			$("#video-info").animate({width:600}, 1000);
			$("#video-info-content").animate({width:510}, 1000);
			
			$("#video-panel-FB-like-header").animate({width:200}, 1000);
			$("#video-panel-FB-like-faces").animate({width:360}, 1000);

			
		} else {
			$( currentNavId ).addClass('current');
			$(".content-body-right").fadeOut(500);
			$( currentSubNavId ).fadeIn(1000);
			$( currentAdId ).fadeIn(1000);
			$( "button", "#sub-nav-close").fadeIn(1000);
			$("#content-body-wrapper", "#content-body").animate({left:'1px'},{queue:true,duration:1000});
			$(".content-body-left").addClass('openNav');
			$(".content-body-full").addClass('content-body-mid');
			
			$(".full-div").animate({width:520}, 1000);
			$(".player").removeClass("bg_large").addClass("bg_medium").css({ 'width' : '512px', 'height' : '288px' });
			$(".player>img").css({'bottom' : '100px', 'left' : '220px'});
			$("div.video-wrapper").css({'padding' : '0px'});
			$(".player>.info").css({ 'width':'482px' });
			$("#video-panel").animate({width:470}, 1000);
			$("#video-info").animate({width:470}, 1000);
			$("#video-info-content").animate({width:380}, 1000);
			
			$("#video-panel-FB-like-header").animate({width:170}, 1000);
			$("#video-panel-FB-like-faces").animate({width:260}, 1000);

		}
	});
	
	$(".mainLink").mouseover(function(){
		var currentNavId = "#" + $(this).attr('id');
		var currentLinkId = "#link-" + $(this).attr('id') + "-bg";
		$( currentLinkId ).stop().animate({left:'0px'},{queue:false, duration:600, easing: 'easeOutCirc'});
	});

	$(".mainLink").mouseout(function(){
		var currentNavId = "#" + $(this).attr('id');
		var currentLinkId = "#link-" + $(this).attr('id') + "-bg";
		if ($(currentNavId).hasClass("current") ){
		} else {
		$( currentLinkId ).stop().animate({left:'200px'},{queue:false, duration:600, easing: 'easeOutCirc'});
		}
	});
	
	// close buttons
	$( "button", ".close-button").button({
            icons: {
                secondary: "ui-icon-close"
            }
	});
	
	$( "button", "#sub-nav-close").click(function(){
		var currentLinkId = "#link-" + $(".current").attr('id') + "-bg";
		$( currentLinkId ).stop().animate({left:'200px'},{queue:false, duration:600, easing: 'easeOutCirc'});
		$(".content-body-right").fadeIn(1000);
		$(this).fadeOut(500);
		$(".sub-nav").fadeOut(500);
		$(".sub-nav-ad").fadeOut(500);
		$("#content-body-wrapper", "#content-body").animate({left:'-201px'},{queue:true,duration:1000, complete: function(){ 
					$(".player").css({ 'width' : '640px', 'height' : '360px' }).removeClass("bg_medium").addClass("bg_large");
				} });
		$(".content-body-left").removeClass('openNav');
		$(".content-body-full").removeClass('content-body-mid');
		$(".mainLink").removeClass('current');
		
		$(".full-div").animate({width:720}, 1000);
		$(".player>img").css({'bottom' : '130px', 'left' : '280px'});
		$("div.video-wrapper").css({'padding' : '0 40px'});
		$(".player>.info").css({ 'width':'610px' });
		$("#video-panel").animate({width:600}, 1000);
		$("#video-info").animate({width:600}, 1000);
		$("#video-info-content").animate({width:510}, 1000);
		
		$("#video-panel-FB-like-header").animate({width:200}, 1000);
		$("#video-panel-FB-like-faces").animate({width:360}, 1000);
		
		
	});
	
	
	// Forms button(s)
	$( "button", ".smiForm").button();
	
	
	// remove search box default text
	$(".searchBox-text").focus(function(srcc){
        if ($(this).val() == $(this)[0].title)
        {
            $(this).removeClass("searchBox-text-active");
            $(this).val("");
        }
    });
    
    $(".searchBox-text").blur(function(){
        if ($(this).val() == "")
        {
            $(this).addClass("searchBox-text-active");
            $(this).val($(this)[0].title);
        }
    });
    
    $(".searchBox-text").blur();
	
	// initialize scrollable
	$(".scrollable").scrollable({circular: false, mousewheel: true});
	
	$(".video-scroll-thumb").hover(
	  function () {
		$(this).find(".video-scroll-info").show("fast");
		$(this).find('marquee').marquee();
	  }, 
	  function () {
		$(this).find(".video-scroll-info").hide("fast");
	  }
	);
	
	// IE fix for link outline border
	$('a').live('mousedown', function(e) { 
		e.target.blur(); 
		e.target.hideFocus = true; 
		e.target.style.outline = 'none';
	}).live('mouseout', function(e) { 
		e.target.blur(); 
		e.target.hideFocus = false; 
		e.target.style.outline = 'none'; 
	});
	
	// IE fix for button outline border
	$('button').live('mousedown', function(e) { 
		e.target.blur(); 
		e.target.hideFocus = true; 
		e.target.style.outline = 'none'; 
	}).live('mouseout', function(e) { 
		e.target.blur(); 
		e.target.hideFocus = false; 
		e.target.style.outline = 'none'; 
	});
	
	// IE fix for image outline border
	$('img').live('mousedown', function(e) { 
		e.target.blur(); 
		e.target.hideFocus = true; 
		e.target.style.outline = 'none'; 
	}).live('mouseout', function(e) { 
		e.target.blur(); 
		e.target.hideFocus = false; 
		e.target.style.outline = 'none'; 
	});
	
	//selec menu
	$('select').selectmenu({style:'dropdown'});
	
	//date picker
	$( "#birthday" ).datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: '1911:2011'
	});
	
	//failsafe for background image
	if ($("#bgimg").is(':hidden')) 
	$("#bgimg").delay(200).fadeIn("slow");
	
	
	// on window resize or scroll, adjust login modal position
	$(window).bind('resize', function(){
		var divWidth=$("#content").width() - 320;
		$(".signin").offset({ top: 20, left: divWidth });
	});
	
	$(window).bind('scroll', function(){
		var divWidth=$("#content").width() - 320;
		var divViewTop = $(window).scrollTop() + 20;
		$(".signin").offset({ top: divViewTop, left: divWidth });
	});

	
	// equal height for grouped divs
	equalHeight($(".content-group"));
	equalHeight($(".content-group-top"));
	equalHeight($(".content-group-video"));
	
	
	//contact form
	$("#contactform").tabs();

	 
});
