/* *****************************************
//  WebTank javascript File
//  Title: most.js
//  File updated: 2012-01-03 13:50:21
// 
//  Do NOT manually edit this generated file
// **************************************** */


/* VARS */

var isFirst = true;

/* INIT */

$.extend( {

	getUrlVars: function() {
	
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		
		for(var i = 0; i < hashes.length; i++) {
		
			hash = hashes[i].split('=');
			
			vars.push(hash[0]);
			
			vars[hash[0]] = hash[1];
			
		}
		
		return vars;
	},
	
	getUrlVar: function( name ) {
		
		return $.getUrlVars()[name];
		
	}
	
} );

var left = ( $.getUrlVar("left") != null ) ? $.getUrlVar("left").toString() : "";
var product_id = ( $.getUrlVar("product_id") != null ) ? $.getUrlVar("product_id").toString() : "";
var video_id = ( $.getUrlVar("video_id") != null ) ? $.getUrlVar("video_id").toString() : "";

//

$(document).ready( function() {
    
	 $("#main").css("top", "25px");
	
	//
	
    $("#thumbnail_container").css("visibility", "hidden");
    
    //
    
    $('#nav #menu li:last').remove();
    
    $("#info span.comma:last-child").remove();
    
    //
    
    $("a[id^='ajax']").fancybox();
    
    //
    
    if( $('#about_menu').size() != '0' ) {
    	updateAbout( 70, id='menu_id_70');
    }
    
    //
    
    if( $("#tshf_container .thumbScroller .container .content").length > 5 ) {
		
		/* 
			ThumbnailScroller function parameters: 
			1) id of the container (div id) 
			2) thumbnail scroller type. Values: "horizontal", "vertical"
			3) first and last thumbnail margin (for better cursor interaction) 
			4) scroll easing amount (0 for no easing) 
			5) scroll easing type 
			6) thumbnails default opacity 
			7) thumbnails mouseover fade speed (in milliseconds) 
		*/
	
		ThumbnailScroller("tshf_container", "horizontal", 0, 800, "easeOutCirc", 1, 300);
	
		//
		
		$("#thumbnail_container .previous").show();
		$("#thumbnail_container .next").show();
		
		//
		
		$("#thumbnail_container .previous").click( function() {
		
			setThumbnailContainer( "previous" );
		
		} );
		
		$("#thumbnail_container .next").click( function() {
		
			setThumbnailContainer( "next" );	
		
		} );
		
	}
	
} );

$(window).load( function() {
	
	$("#thumbnail_container").css("visibility", "visible");
	
	//
	
	if( $(".thumbScroller .horWrapper .container").length != 0 && left != "" ) {
		
		$(".thumbScroller .horWrapper .container").css("left", left + "px");
		
	}
	
	if( product_id != "" ) {
		
		$(".thumbScroller .horWrapper .container a[id=thumb_id_" + product_id + "] img").css("height", "73px");
		$(".thumbScroller .horWrapper .container a[id=thumb_id_" + product_id + "] img").css("border", "1px solid #000000");
		
	}
	
	if( video_id != "" ) {
		
		$(".thumbScroller .horWrapper .container a[id=thumb_id_" + video_id + "] img").css("height", "73px");
		$(".thumbScroller .horWrapper .container a[id=thumb_id_" + video_id + "] img").css("border", "1px solid #000000");
		
	}
	
	/*  */
	
	$("#thumbnail_container .thumbnails .content a:first").click( function() {
		
		if( isFirst ) {
		
			isFirst = false;
			
		} else {
			
			reloadPage( $(this).attr("rel") );
		
		}
	
	} );
	
	$("#thumbnail_container .thumbnails .content a:not(:first)").click( function() {
		
		reloadPage( $(this).attr("rel") );
	
	} );
	
	//
	
	$("#thumbnail_container .thumbnails .content a").mouseover( function() {
		
		$("#content .tooltip").remove();
		
		//
		
		$("#content").append("<div class='tooltip'>" + $(this).attr("title") + "</div>")
		
	} );
	
	//
	
	$("#thumbnail_container .thumbnails .content a:first").click();
	
} );
	
// FUNCTIONS

function reloadPage( url ) {

	var position = $(".thumbScroller .horWrapper .container").position();

	window.location.href = url + "&left=" + position.left; 
	
}

function setPhotobook() {

	$('#photobook .about_image:not(:first-child)').hide();
	
	$("a[class^='about_image']").fancybox();
	
}

function updateImage( src ) {
							
	$("img#rollover").attr("src", src);
	
}

function setThumbnailContainer( position ) {
	
	var pos = 0;
	var container = $("#tshf_container .thumbScroller .container");
	var width = $("#thumbnail_container").width();
	var items = $("#tshf_container .thumbScroller .container .content").length;
	var item_width = $("#tshf_container .thumbScroller .container .content").width();
	
	switch( position ) {
	
		case "previous":
			
			if( parseInt( container.css("left") ) < 0 ) {
				
				pos = ( parseInt( container.css("left") ) + 107 ) + "px";
				
				container.stop().animate( {left: pos}, 800, "easeOutCirc" );
	
			}
			
		break;
		
		case "next":
			
			if( parseInt( container.css("left") ) > parseInt( width - ( items * item_width ) ) ) {
				
				pos = ( parseInt( container.css("left") ) - 107 ) + "px";
				
				container.stop().animate( {left: pos}, 800, "easeOutCirc" );
	
			}
			
		break;
		
	}						
	
}

