/* 
	Star Musician of Iran 
	© 2011 www.starmusician.com  
	version 1.0          
*/


/*=======================*/
/*   jQuery Functions    */
/*=======================*/

// if element is in view
function isScrolledIntoView(elem)
{
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom)
      && (elemBottom <= docViewBottom) &&  (elemTop >= docViewTop) );
}

// Fullscreen image background
function FullScreenBackground(theItem,theContainer){
		var winWidth=$(window).width();
		var winHeight=$(window).height();
		var imageWidth=$(theItem).width();
		var imageHeight=$(theItem).height();
		var picHeight = imageHeight / imageWidth;
		var picWidth = imageWidth / imageHeight;
		if ((winHeight / winWidth) < picHeight) {
			$(theItem).css("width",winWidth);
			$(theItem).css("height",picHeight*winWidth);
		} else {
			$(theItem).css("height",winHeight);
			$(theItem).css("width",picWidth*winHeight);
		};
		$(theContainer).css("width",winWidth);
		$(theContainer).css("height",winHeight);
		$(theItem).css("margin-left",(winWidth- $(theItem).width()));
		$(theItem).css("margin-top",(winHeight- $(theItem).height()));
		//$(theItem).css("margin-left",(winWidth- $(theItem).width())/2);
		//$(theItem).css("margin-top",(winHeight- $(theItem).height())/2);
	}
	
// Equalize height of columnsin group
function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	if(tallest > 500) {
		group.height(tallest);
	} else {
		group.height(500); // set minimum height of 500px for all content areas	
	}
}

// When to show page scroller buttons
function sizeWindow(elem) {
	if (elem.height() > $(window).height()){
		$("#nav_up").hide();
		$("#nav_down").fadeIn('slow');  
	} else {
		$("#nav_down").hide(); 
		$("#nav_up").fadeIn('slow');	
	}
}

// Check if element is in view in browser
function isScrolledIntoView(elem)
{
	var docViewTop = $(window).scrollTop();
	var docViewBottom = docViewTop + $(window).height() - 80;

	var elemTop = $(elem).offset().top;
	var elemBottom = elemTop + $(elem).height();

	return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
}


// Loging SMI user
function login(){
	window.location = "/login/logout.cfm"
}

// Logout SMI user
function logout(){
	window.location = "/login/logout.cfm";
}

// Logout Facebook user
function logoutFB(){
		FB.logout(function(response) { window.location = "/login/logout.cfm" });
}

// Show loading animation
function loading(){
	$("#loading").show();
}


