// JavaScript Document// JavaScript Document
$(document).ready(function() {
$("#rt").val(0);
$("#lt").val(0);
var $closed=1;
function propermargin(){
var ttlheight = $('.cheader').height()+$('.ccontent').height()+$('#orderbutton').height()+70;
if(ttlheight>350)
$('#content').css('height',ttlheight);
else
$('#content').css('height',350);
var height=$("#starback").height();
$(".cheader").css('margin-top',(0-(height-30)));
var popheight =$('#pop').height()||530;
	var mypos=$('.image_reel img:first').offset();
	var curentop = mypos.top-popheight+5;
	var maxleft=$(window).width()-590;
	var myflag=0;
	$('#pop').css("left", mypos.left);  
	//alert(curentop);   
	$('#pop').css("top", curentop);
	$('body').append('<div id="popcloser" style="display:none; position:absolute; width:100%; height:100%; z-index:100;"></div>');
	var myh = $(document).height();
	$('#popcloser').css('height', myh-40);
}

propermargin();
$(window).resize(function() {propermargin();});

$("a #rightarrow").click(function() {
var curleft=$(".image_reel").css('left');
		closepop();
		var rot =$("#rt").val();
		rot=rot-268;
		var imageSum = $(".image_reel img").size();
		var imageReelWidth = 0-((290 * imageSum)-document.body.clientWidth);
		$(".image_reel").animate({ 
			left: '-=268px'
		}, 500, function() {
    	// Animation complete.
		$(".image_reel").animate({ 
			left: '+=268px'
		}, 0 ,function(){
			$(".image_reel").append($(".image_reel img:first")); 
			});
  							});
		return false;					
});
$("#popcloser").click(function(){closepop()})
$("a #leftarrow").click(function() {
		closepop();
var curleft=$(".image_reel").css('left');
		var rot =$("#rt").val();
		rot=rot+268;
		var imageSum = $(".image_reel img").size();
		var imageReelWidth = 0-((290 * imageSum)-document.body.clientWidth);
		$(".image_reel").animate({ 
			left: '-=268px'
		}, 0 ,function(){$(".image_reel").prepend($(".image_reel img:last")); });
		$(".image_reel").animate({ 
			left: '+=268px'
		}, 500, function() {
    	// Animation complete.
  							});
		return false;
});

$('.image_reel img').click(function(e) {
	
	$('#pop').css('display','none');
	var img= $(this).attr("alt");
	var title= $(this).attr("title");
	$('#pophdr').html(title);
	$.mypos=$(this);
$.myflag=0;
if(img!='')
{
	$('#lloader').attr('src','/images'+img);
$('#lloader').load(function() {
if($.myflag==0)
{
	$('#lloader').css('margin','0 auto');
	$('#lloader').css('display','block');
	
		
	var popheight =$('#pop').height()||530;
	var mypos=$.mypos.offset();

	var curentop = mypos.top-popheight+5;
	var maxleft=$(window).width()-560;
	var myflag=0;
	while(mypos.left>maxleft)
	{
		$("#rightarrow").trigger("click");
                            mypos.left=mypos.left-268;
		myflag++;		
		}
	$('#pop').css("left", mypos.left);     
	$('#pop').css("top", curentop);
	$('#pop').css("z-index", 200);
	var mytimer=0;
	while(myflag!=0)
	{
		mytimer=mytimer+500;
		myflag--;
		}
			setTimeout(function() {
				
			 if ($.browser.msie) {
				 $('#pop').css('display','block');
				 $('#popcloser').css('display','block');
			  }
			  else
			  {
				$('#pop').fadeIn('slow', function() {});
				$('#popcloser').css('display','block');
			  }
			},mytimer);

$.myflag=1;
}	
});
          }
	});
	return false;
});
function closepop(){
	$('#popcloser').css('display','none');
	 if ($.browser.msie) 
	 {
		 var $closed=1;
	 $('#pop').css('display','none');
  	}
  	else
  	{
	$('#pop').fadeOut('slow', function() {});
  	}
	  return false;
	};
