var total_slides;
var slides_enable;
var current_slide;

$(document).ready(function() {
	// video preview
	$('.homepage_video a').click(function(event){
		event.preventDefault();
		var contentOffset = $('.content').offset(); 
		
		$('.homepage_video_dialog').modal({
			autoPosition: false,
			containerCss: {
				top:  0,
				left: (contentOffset.left - 90) + 'px'
			}
		});
	});
	
	$(".colorbox").colorbox({width:"600px", opacity:0.5});
				// $(".example7").colorbox({width:"80%", height:"80%", iframe:true});
	
if($('.slides').length){
	$(function(){
	  var $homepageVideo = $(".homepage_video"),
	  	  $lastSlide = $(".homepage_slideshow li:last img");
	  
	  $('.slides').slides({
		play: 4000,
		preload: true,
		generatePagination: false,
		effect: 'fade',
		crossfade: true,
		animationStart: function() {
			var $currSlide = $(".homepage_slideshow li:visible img"),
				isLastSlide = $currSlide.attr('src') == $lastSlide.attr('src'); 
			
			if (isLastSlide && $homepageVideo.is(':visible')) {
				$homepageVideo.fadeOut(350);
			}
			else {
				$homepageVideo.fadeIn(350);
			}
			
		}
		
	  });
	});
	}
	// $('.navmenu>li').css('overflow', 'hidden');
	$('.navmenu>li').hover(
		function(){
			$(this).find('ul').css('display','block');
		},
		function(){
			$(this).find('ul').css('display','none');
		}
	);

	$('.sidebar_overlay').css('opacity','0.8');

	// if($('.main_collumn img').length){
	// 	
	// 	$('.main_collumn img').wrap('<span class="inline_image" />');
	// 	var imgtitle;
	// 	var imgalt;
	// 	var imgall;
	// 	$('.inline_image img').each(function(){
	// 					imgalt=$(this).attr("alt");
	// 					imgtitle=$(this).attr("title");
	// 					if(imgalt && imgtitle){
	// 						imgall=imgalt+' - '+imgtitle;
	// 					}else{
	// 						imgall=imgalt+imgtitle;
	// 					}
	// 					if(imgall!=""){
	// 						$(this).parent().append('<span>'+imgall+'</span>');
	// 					}
	// 			});
	// }



	if($('.collection_list').length){		
		
			total_slides =$('.collection_list li').length;

			var slides_width = total_slides * 333;

			$('.collection_list').css('width',slides_width);
			slides_enable = true;
			current_slide=0;
			$('.collection_next').click(function(){
				if (slides_enable){	
					if (current_slide<(total_slides-2)){
						slides_enable = false;
						current_slide++;				
						animateslide();
					}
				}
			});
			$('.collection_prev').click(function(){
				if (slides_enable){	
					if (current_slide>0){
						slides_enable = false;
						current_slide--;
						animateslide();
					}
				}
			});
			
			$('.collection_list .item_info a').toggle(
			      function () {
			        $(this).closest('.item_info').stop().animate({top : 509-$(this).closest('.item_info').height()}, 200, function(){
								$(this).find('span').text('-');
							});
			      },
			      function () {
			        $(this).closest('.item_info').stop().animate({top : 479}, 100, function(){
								$(this).find('span').text('+');								
							});
			      }
			    );
	}
	
	// 
	// $("li").hover(
	//   function () {
	//     $(this).append($("<span> ***</span>"));
	//   }, 
	//   function () {
	//     $(this).find("span:last").remove();
	//   }
	// 
	
	// // insert buttons rounded corners
	// $('.button').prepend('<span class="btn_start"></span>').append('<span class="btn_end"></span>');
	// // insert rounded corners
	// $('.rounded').append('<div class="rounded_lt"></div><div class="rounded_rt"></div><div class="rounded_l"></div><div class="rounded_r"></div><div class="rounded_lb"></div><div class="rounded_rb"></div>');
	// //rounded cornens height fix
	// $('.rounded_l, .rounded_r').each(function(){
	// 	$(this).height($(this).closest('.rounded').innerHeight()-55);
	// });
	// $('.footer_left_corners, .footer_right_corners').height($('.footer').innerHeight()-30);
	// 
	// //slider
	// 	total_slides =$('.thumbs_slider ul li').length;
	// 	
	// 	var slides_width = total_slides * 128;
	// 	
	// 	$('.thumbs_slider ul').css('width',slides_width);
	// 	slides_enable = true;
	// 	current_slide=0;
	// 	$('.thumbs_slider .next_slide').click(function(){
	// 		if (slides_enable){	
	// 			if (current_slide<(total_slides-5)){
	// 				slides_enable = false;
	// 				current_slide++;				
	// 				animateslide();
	// 			}
	// 		}
	// 	});
	// 	$('.thumbs_slider .prev_slide').click(function(){
	// 		if (slides_enable){	
	// 			if (current_slide>0){
	// 				slides_enable = false;
	// 				current_slide--;
	// 				animateslide();
	// 			}
	// 		}
	// 	});	
	// 	
	// //popups
	// $(".show_error_popup").colorbox({close:"", inline:true, href:"#error_popup"});
	// $(".show_deposit_popup").colorbox({close:"", inline:true, href:"#deposit_popup"});
});
// functions
 function animateslide(){
		if($('body').css('direction')=='rtl'){
			$('.collection_list').animate({right: (current_slide-1) * -333}, 300, function() {	slides_enable = true; });
		}else{
			$('.collection_list').animate({left: (current_slide-1) * -333}, 300, function() {	slides_enable = true; });
		}		
  }
