// JavaScript Document


//========================navigation==============
$(function() {
	$('li').hover(function(){
		$(this).find('a').animate({marginTop: "5"},{queue:false,duration:250});
	}, function(){
		$(this).find('a').animate({marginTop: "0"},{queue:false,duration:400});
	});
});

//==========================================


$(function()
{
	
	  animateheaderlogo();
	  $('.scrollbar').scrollbar();


	  $('#demo1 a').click(function(ev){
		  ev.preventDefault();
		  $('#container1').scrollbar('scrollto', $('.scrollbar:first li:eq(24)'));
	  });


	  $('#demo2 a:first').click(function(ev){
		  ev.preventDefault();
		  $('#demo2').find('.scrollbar-pane').children(':first').clone().appendTo('.scrollbar-pane');
		  $('#container2').scrollbar('repaint');
	  });
	  $('#demo2 a:last').click(function(ev){
		  ev.preventDefault();
		  $('#demo2').find('.scrollbar-pane').children(':first').remove();
		  $('#container2').scrollbar('repaint');
	  });
				
	
	
	butterflyanimation();
	$("#mirror_id").animate(
	{
		'margin-left': '30px'
	},600);
	
//					alert($(".footer").height())
//					
//					alert($(window).height());
//					
	/*alert(parseInt(parseInt($(document).height()) - parseInt($(".footer").height()))+'px');*/
	/*alert(parseInt(parseInt(parseInt($(document).height()) *10.5)/100));
	$(".footer").css(
	{
		'margin-top' : parseInt(parseInt(parseInt(parseInt($(document).height()) *10.5)/100))+'px'
	})*/

	loadgallery();
});


function loadgallery()
{
//=========================================== for gallery section starts from here	=====================
	setdefault();
	$(".img_thumb").find("img").bind('mouseover',function()
	{
		$(this).parent().animate(
		{
			'filter': 'alpha(opacity=100)',
			'-khtml-opacity': '1.00',  
			'-moz-opacity': '1.00',
			'opacity': '1.00'
		},200);
	}).bind('mouseout',function()
	{
		var getid = currentselected_thumb();
		//alert(getid);
		if(getid != $(this).attr('id'))
		{
			$(this).parent().animate(
			{
				'filter': 'alpha(opacity=50)',
				'-khtml-opacity': '.5',  
				'-moz-opacity': '.5',
				'opacity': '.5'
			},200);
		}
		
		
	}).bind('click',function()
	{
		resetolder();
		setnew($(this).attr('id'))
		changeimageonclick($(this).attr('id'),$(this).attr('alt'),'load')
		

	});
	
	if($("#bigimage_image2").length > 0)
	{
		$("#bigimage_image2").css(
		{
			'filter': 'alpha(opacity=0)',
			'-khtml-opacity': '0.0',  
			'-moz-opacity': '0.0',
			'opacity': '0.0'
		});
	}
	
	
	
	
//=========================================== for gallery section ends here	=====================
	

}

function animateheaderlogo()
{
	if($("#firstimageleft").length > 0 && $("#firstimageright").length > 0 && $("#secondimageleft").length > 0 && $("#secondimageright").length > 0 && $("#thirdimageleft").length > 0 && $("#thirdimageright").length > 0)
	{
		$("#firstimageleft").animate(
		{
			'height' : '41px',
			'top':'27px',
			'width':'20px'
		},600);
		$("#firstimageright").animate(
		{
			'height' : '41px',
			'top':'27px',
			'width':'20px'
			
		},600);

		$("#secondimageleft").animate(
		{
			'height' : '76px',
			'top':'2px',
			'width':'52px'
			
		},700);
		$("#secondimageright").animate(
		{
			'height' : '76px',
			'top':'2px',
			'width':'52px'
		},700);

		$("#thirdimageleft").animate(
		{
			'width':'123px',
			'height':'74px',
			'top':'16px',
			'margin-left':'-103px'
			
		},800);
		$("#thirdimageright").animate(
		{
			'width':'123px',
			'height':'89px',
			'top':'10px',
			'margin-left':'100px'
			
		},800);
		
		
	}
}


function butterflyanimation()
{
	$("#headerid").animate(
	{
		'margin-left': '0px'
	},600,function()
	{
		$("#headertext-image").animate(
		{
			'margin-top': '-30px',
			'margin-right' : 0,
			'margin-bottom' : '-20px',
			'margin-left' : '-48px',
			'width' : '62px',
			'height' : '100px'
		},600,function()
		{
			
			$("#butterfly").fadeIn('100',function()
			{
				$('#butterfly').vibrate(
				{
					duration:	100, 
					frequency:	100, 
				});
				$('#butterfly').animate(
				{
					'margin-left' : '180px', 
					'margin-top': '15px'
				},2000,function()
				{
					$('#butterfly').animate(
					{
						'margin-left' : '190px', 
						'margin-top': '-15px',
						'filter': 'alpha(opacity=00)',
						'-khtml-opacity': '0.0',
						'-moz-opacity': '0.0',
						'opacity': '0.0'
					},2000);
					
					
					/*setTimeout(function()
					{
						$("#butterfly").fadeOut(1000,function()
						{
							$('#butterfly').vibrate().remove();
						});
						
					},1);*/
				});

			});
			
			$("#butterfly2").fadeIn('100',function()
			{
				$('#butterfly2').vibrate(
				{
					duration:	100, 
					frequency:	100, 
				});
				$('#butterfly2').animate(
				{
					'margin-left' : '230px', 
					'margin-top': '10px'
				},2000,function()
				{
					$('#butterfly2').animate(
					{
						'margin-left' : '180px', 
						'margin-top': '15px',
						'filter': 'alpha(opacity=00)',
						'-khtml-opacity': '0.0',
						'-moz-opacity': '0.0',
						'opacity': '0.0'
					},2000);
					
					
					
					
					/*setTimeout(function()
					{
						$("#butterfly2").fadeOut(1000,function()
						{
							$('#butterfly2').vibrate().remove();
						});
						
					},1);*/
				});

			});
			
			$("#butterfly3").fadeIn('100',function()
			{
				
				$('#butterfly3').vibrate(
				{
					duration:	100, 
					frequency:	100, 
				});
				$('#butterfly3').animate(
				{
					'margin-left' : '190px', 
					'margin-top': '70px'
				},2000,function()
				{
					
					$('#butterfly3').animate(
					{
						'margin-left' : '190px', 
						'margin-top': '30px',
						'filter': 'alpha(opacity=00)',
						'-khtml-opacity': '0.0',
						'-moz-opacity': '0.0',
						'opacity': '0.0'
					},2000);
					
					/*setTimeout(function()
					{
						$("#butterfly3").fadeOut(1000,function()
						{
							$('#butterfly3').vibrate().remove();
						});
						
					},1);*/
				});

			});
			
			
		});
	});
}





function changeimageonclick(id,alt,type)
{
	//alert(id+'~~~~'+alt);
	$("#currentselected_thumb").val(id)
	var imagesrc = alt;
	
	//imagesrc = imagesrc.replace(/_thumb/,'');
	//imagesrc = imagesrc.replace(/.jpg/,'.png');
	//alert(imagesrc);
	var currentselected_div = currentselected();
	
	
	//if(imagesrc)
	
	//alert(currentselected_div);
	if(currentselected_div == 'bigimage_image1')
	{
		if($("#bigimage_image1").attr('src') != imagesrc)
		{
			$("#bigimage_image2").attr('src',imagesrc);
			$("#bigimage_image1").animate(
			{
				'filter': 'alpha(opacity=0)',
				'-khtml-opacity': '0.0',  
				'-moz-opacity': '0.0',
				'opacity': '0.0'
			},500,function()
			{
				$("#bigimage_image1").attr('src','');
			});
			
			if(type == 'ajax')
			{
				$("#bigimage_image2").animate(
				{
					'filter': 'alpha(opacity=100)',
					'-khtml-opacity': '1.0',  
					'-moz-opacity': '1.0',
					'opacity': '1.0'
				},500,function()
				{
					setdefault();
				});
			}
			else
			{
				$("#bigimage_image2").animate(
				{
					'filter': 'alpha(opacity=100)',
					'-khtml-opacity': '1.0',  
					'-moz-opacity': '1.0',
					'opacity': '1.0'
				},500);
			}
		}
		
		
	}
	else
	{
		if($("#bigimage_image2").attr('src') != imagesrc)
		{
			$("#bigimage_image1").attr('src',imagesrc);
			$("#bigimage_image2").animate(
			{
				'filter': 'alpha(opacity=0)',
				'-khtml-opacity': '0.0',  
				'-moz-opacity': '0.0',
				'opacity': '0.0'
			},500,function()
			{
				$("#bigimage_image2").attr('src','');
			});
			
			if(type == 'ajax')
			{
				$("#bigimage_image1").animate(
				{
					'filter': 'alpha(opacity=100)',
					'-khtml-opacity': '1.0',  
					'-moz-opacity': '1.0',
					'opacity': '1.0'
				},500,function()
				{
					setdefault();
				});
			}
			else
			{
				$("#bigimage_image1").animate(
				{
					'filter': 'alpha(opacity=100)',
					'-khtml-opacity': '1.0',  
					'-moz-opacity': '1.0',
					'opacity': '1.0'
				},500);
				
			}
		}
		
		
	}
	;
}


function currentselected()
{
	var get_current_select = $("#bigimage_image1").css('opacity');
	if(get_current_select > 0)
	{
		return 'bigimage_image1';
	}
	else
	{
		return 'bigimage_image2';
	}
	//alert(get_current_select);
}


function currentselected_thumb()
{
	var return_id = $("#currentselected_thumb").val();
	return return_id;
}

function resetolder()
{
	var getid = currentselected_thumb();
	$("#"+getid).parent().css(
	{
		'filter': 'alpha(opacity=50)',
		'-khtml-opacity': '.5',  
		'-moz-opacity': '.5',
		'opacity': '.5'
	});
}

function setnew(getid)
{
	$("#"+getid).parent().css(
	{
		'filter': 'alpha(opacity=100)',
		'-khtml-opacity': '1.0',  
		'-moz-opacity': '1.0',
		'opacity': '1.0'
	});
}

function setdefault()
{
	var get_current_id = currentselected();
	var defaultsrc = $("#"+get_current_id).attr('src');
	var findall = $(".main_img_left").find(".img_thumb img");
	//alert("get_current_id=="+get_current_id)
	findall.each(function()
	{
		//alert($(this).attr('alt')+'~~~~~~~'+defaultsrc);
		if($(this).attr('alt') == defaultsrc)
		{
			//alert('tttt');
			$(this).parent().css(
			{
				'filter': 'alpha(opacity=100)',
				'-khtml-opacity': '1.0',  
				'-moz-opacity': '1.0',
				'opacity': '1.0'
			});
			$("#currentselected_thumb").val($(this).attr('id'));
		}
	});
	
	
}
