$(document).ready(function() {

	$('#background_selector a').bind('click', function() {
		var background_id = $(this).attr("id");

		$.ajax({
		type:"post",
		data:"background_id="+background_id,
		url: BASE_URL+"/setbackground.php",
			success:function(data){
				if(data == 1)
				{
					location.reload();
				}
			}
		});
	});	

	jQuery('#carousel').jcarousel({

		vertical: false,

		scroll: 1,

		wrap: "circular",

		visible: 1,
		
		buttonNextHTML: null, 
		
		buttonPrevHTML: null,

		auto: 10,
		itemVisibleInCallback:  highlight,

		itemVisibleOutCallback: removehighlight,

		itemLastInCallback:   mycarousel_itemLastInCallback,

		itemLastOutCallback:  mycarousel_itemLastOutCallback,

		initCallback: mycarousel_initCallback

	});

	jQuery('#box-scroll').jcarousel({

		vertical: true,

		scroll: 2,

		wrap: "circular",

		visible: 2,

		auto: 4

	});
	
	jQuery('#smallProdImage').live('click',function(){
	
		var path_value = jQuery(this).attr("src");
		jQuery('#largProdImage').attr("src", path_value);
		
	});

});

/**

 * This is the callback function which receives notification	
 * when an item becomes the first one in the visible range.	
 */

function mycarousel_itemLastInCallback(carousel, item, idx, state) {	    

};

/**	
 * This is the callback function which receives notification	
 * when an item is no longer the first one in the visible range.	
 */

function mycarousel_itemLastOutCallback(carousel, item, idx, state) {

	var tnpis = jQuery('#tnps').val();	
	var turl_value = jQuery('#turl').val();	
	//alert(tnpis);	
	if(idx == tnpis)	
	{
			carousel.scroll(jQuery.jcarousel.intval(1));	
		jQuery('#jcarousel-control div:nth-child('+ tnpis +')').attr("class","slide_deactive123");	
		return true; 	
	}	

};

function highlight(carousel, obejctli,liindex,listate){

	//alert(listate);	
	var turl_value = jQuery('#turl').val();	
	 jQuery('#jcarousel-control div:nth-child('+ liindex +')').attr("class","slide_active");	
};

// it will remove last selected slide from <a>	
// <a href="#" class="selected">1</a> to <a href="#">1</a>

function removehighlight(carousel, obejctli,liindex,listate){

	var turl_value = jQuery('#turl').val();	
	 jQuery('#jcarousel-control div:nth-child('+ liindex +')').attr("class","slide_deactive123");

};

function mycarousel_itemFirstInCallback(carousel, item, id, state) {

	//alert(state);

};

function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {

	

};

/**	
 * This is the callback function which receives notification	
 * when an item becomes the first one in the visible range.	
 * Triggered after animation.	
 */

function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {

};

function mycarousel_initCallback(carousel) {  
   jQuery('#jcarousel-control div').bind('click', function() {
		slide_name = $(this).attr("id");
		slide_name = slide_name.split('_');
		slide_id = slide_name[1];
		carousel.scroll(jQuery.jcarousel.intval(slide_id));
	  return false; 
	});
};
