$(function(){

$("img").load(function(evt){
      $(this).fadeIn(1000);
});

$(".image_thmb img").live("load",function () { $(this).fadeIn(); });
$("#big-img").load(function () { $("#big-img").fadeIn(); });
$("#more_image img").load(function () {$(this).fadeIn(); });
/*
$("#big-img").hide();
$("#more_image img").hide();
$(".image_thmb img").hide();
*/

/*
$("#more_image img").hide();

$("#big-img").load(function () {
$("#big-img").fadeIn();
});
*/



$("#src").hide();
$("#total").hide();

if($("#en_site").text()=='en'){
var images_gallery_folder="../img/gallery/";	
var images_folder="../img/";	
}else{
var images_gallery_folder="../img/gallery/";
var images_folder="../img/";		
}



var total=Math.round(((eval($("#total").html()))));
var domain=$("#domain").text();
var cat=$("#image_thmb_cont1").attr("cat");
var cat_name=$("#image_thmb_cont1").attr("cat_name");

$("#over").hide();
$("#big-div-cont").hide();

//alert(images_gallery_folder);
//alert(total);


var window_height=$(document).height();
var number;

$("#over").css({"height":window_height+"px"});

$(".image_thmb_cont").live("click",function(){
number=($(this).attr("lang"));
real_number=($(this).attr("dir"));

$("#big-div").show();
$("#big-div-cont").show();

$("#more_image img").hide();
$("#more_image img").css("opacity","0.5");
$("#more_image img").css("filter","alpha(opacity=50)");
$("#more_image #more_img1").css("opacity","1");
$("#more_image #more_img1").css("filter","alpha(opacity=100)");


$("#image-close").slideDown(500);
$("#image-code").html($("#code" + number).html());
$("#image-title").text($("#title" + number).text());
$("#image-desc").text($("#desc" + number).text());
$("#image-price").text($("#price" + number).text());
$("#image-more").html($("#more" + number).html());



$("#big-img").attr("src","");


$("#big-img").attr("src",images_gallery_folder+"img"+real_number+".jpg");
$("#more_img1").attr("src",images_gallery_folder+"img"+real_number+".jpg");
$("#more_img2").attr("src",images_gallery_folder+"img"+real_number+"_1.jpg");
$("#more_img3").attr("src",images_gallery_folder+"img"+real_number+"_2.jpg");
$("#more_img4").attr("src",images_gallery_folder+"img"+real_number+"_3.jpg");
$("#more_img5").attr("src",images_gallery_folder+"img"+real_number+"_4.jpg");


$("#over").show();




$("#short_url").html("http://"+domain+"/product.php?id="+real_number+"&cat="+cat+"&cat_name="+cat_name);
$("#image_page").attr("href","http://"+domain+"/product.php?id="+real_number+"&cat="+cat+"&cat_name="+cat_name);
$.post("update_view.php",{"id":real_number});

$("#face_comment").html('');
$("#social_share").html('');

FB.XFBML.parse();
$("#face_comment").load("load_comment.php",{'domain':domain ,'id':real_number},function(){
FB.XFBML.parse();
});
FB.XFBML.parse();
$("#social_share").load("load_social.php",{'domain':domain ,'id':real_number},function(){
FB.XFBML.parse();
});


});		   

$("#close").click(function(){
$("#big-div").hide(200);
$("#big-div-cont").hide();
$("#over").hide(200);

});	

$("#image-next").click(function(){
if (number<total ){

$("#more_image img").hide();
$("#more_image img").css("opacity","0.5");
$("#more_image img").css("filter","alpha(opacity=50)");
$("#more_image #more_img1").css("opacity","1");
$("#more_image #more_img1").css("filter","alpha(opacity=100)");

$("#big-img").attr("src","");
$("#big-img").attr("src",images_folder+"empty.jpg");
real_number=$("#image_thmb_cont"+Math.round(eval(number)+1)).attr("dir");
var img_src=(images_gallery_folder+"img"+real_number+".jpg");

$("#mag_big").hide();

$("#big-img").attr("src","");
$("#big-img").attr("src",images_folder+"empty.jpg");

$("#big-img").attr("src",img_src);
$("#more_img1").attr("src",images_gallery_folder+"img"+real_number+".jpg");
$("#more_img2").attr("src",images_gallery_folder+"img"+real_number+"_1.jpg");
$("#more_img3").attr("src",images_gallery_folder+"img"+real_number+"_2.jpg");
$("#more_img4").attr("src",images_gallery_folder+"img"+real_number+"_3.jpg");
$("#more_img5").attr("src",images_gallery_folder+"img"+real_number+"_4.jpg");




$("#image-code").html($("#code" + Math.round(eval(number)+1)).html());
$("#image-title").text($("#title" + Math.round(eval(number)+1)).text());
$("#image-desc").text($("#desc" + Math.round(eval(number)+1)).text());
$("#image-price").text($("#price" + Math.round(eval(number)+1)).text());
$("#image-more").html($("#more" + Math.round(eval(number)+1)).html());

$("#short_url").html("http://"+domain+"/product.php?id="+real_number+"&cat="+cat+"&cat_name="+cat_name);
$("#image_page").attr("href","http://"+domain+"/product.php?id="+real_number+"&cat="+cat+"&cat_name="+cat_name);
$.post("update_view.php",{"id":real_number});

$("#face_comment").html('');
$("#social_share").html('');



number=eval(number)+1;

FB.XFBML.parse();
$("#face_comment").load("load_comment.php",{'domain':domain ,'id':real_number},function(){
FB.XFBML.parse();
});
FB.XFBML.parse();
$("#social_share").load("load_social.php",{'domain':domain ,'id':real_number},function(){
FB.XFBML.parse();
});


}else{
$("#big-img").attr("src","");
$("#big-img").attr("src",images_folder+"empty.jpg");
real_number=$("#image_thmb_cont1").attr("dir");
var img_src=(images_gallery_folder+"img"+real_number+".jpg");

$("#more_image img").hide();
$("#more_image img").css("opacity","0.5");
$("#more_image img").css("filter","alpha(opacity=50)");
$("#more_image #more_img1").css("opacity","1");
$("#more_image #more_img1").css("filter","alpha(opacity=100)");

$("#big-img").attr("src",img_src);
$("#more_img1").attr("src",images_gallery_folder+"img"+real_number+".jpg");
$("#more_img2").attr("src",images_gallery_folder+"img"+real_number+"_1.jpg");
$("#more_img3").attr("src",images_gallery_folder+"img"+real_number+"_2.jpg");
$("#more_img4").attr("src",images_gallery_folder+"img"+real_number+"_3.jpg");
$("#more_img5").attr("src",images_gallery_folder+"img"+real_number+"_4.jpg");




$("#image-code").html($("#code1").html());
$("#image-title").text($("#title1").text());
$("#image-desc").text($("#desc1").text());
$("#image-price").text($("#price1").text());
$("#image-more").html($("#more1").html());

$("#short_url").html("http://"+domain+"/product.php?id="+real_number+"&cat="+cat+"&cat_name="+cat_name);
$("#image_page").attr("href","http://"+domain+"/product.php?id="+real_number+"&cat="+cat+"&cat_name="+cat_name);
$.post("update_view.php",{"id":real_number});

$("#face_comment").html('');
$("#social_share").html('');

number=1;


FB.XFBML.parse();
$("#face_comment").load("load_comment.php",{'domain':domain ,'id':real_number},function(){
FB.XFBML.parse();
});
FB.XFBML.parse();
$("#social_share").load("load_social.php",{'domain':domain ,'id':real_number},function(){
FB.XFBML.parse();
});


}
});	


$("#image-prev").click(function(){
if (number>1 ){
$("#big-img").attr("src","");
$("#big-img").attr("src",images_folder+"empty.jpg");
real_number=$("#image_thmb_cont"+Math.round(eval(number)-1)).attr("dir");
var img_src=(images_gallery_folder+"img"+real_number+".jpg");
$("#mag_big").hide();

$("#more_image img").hide();
$("#more_image img").css("opacity","0.5");
$("#more_image img").css("filter","alpha(opacity=50)");
$("#more_image #more_img1").css("opacity","1");
$("#more_image #more_img1").css("filter","alpha(opacity=100)");

$("#big-img").attr("src",img_src);
$("#more_img1").attr("src",images_gallery_folder+"img"+real_number+".jpg");
$("#more_img2").attr("src",images_gallery_folder+"img"+real_number+"_1.jpg");
$("#more_img3").attr("src",images_gallery_folder+"img"+real_number+"_2.jpg");
$("#more_img4").attr("src",images_gallery_folder+"img"+real_number+"_3.jpg");
$("#more_img5").attr("src",images_gallery_folder+"img"+real_number+"_4.jpg");


$("#image-code").html($("#code"+Math.round(eval(number)-1)).html());
$("#image-title").text($("#title"+Math.round(eval(number)-1)).text());
$("#image-desc").text($("#desc"+Math.round(eval(number)-1)).text());
$("#image-price").text($("#price"+Math.round(eval(number)-1)).text());
$("#image-more").html($("#more"+Math.round(eval(number)-1)).html());
$("#short_url").html("http://"+domain+"/product.php?id="+real_number+"&cat="+cat+"&cat_name="+cat_name);
$("#image_page").attr("href","http://"+domain+"/product.php?id="+real_number+"&cat="+cat+"&cat_name="+cat_name);
$.post("update_view.php",{"id":real_number});

$("#face_comment").html('');
$("#social_share").html('');

number=eval(number)-1;

FB.XFBML.parse();
$("#face_comment").load("load_comment.php",{'domain':domain ,'id':real_number},function(){
FB.XFBML.parse();
});
FB.XFBML.parse();
$("#social_share").load("load_social.php",{'domain':domain ,'id':real_number},function(){
FB.XFBML.parse();
});



 }
else{
$("#big-img").attr("src","");
$("#big-img").attr("src",images_folder+"empty.jpg");
real_number=$("#image_thmb_cont"+total).attr("dir");
var img_src=(images_gallery_folder+"img"+real_number+".jpg");
$("#big-img").attr("src",img_src);

$("#more_image img").hide();
$("#more_image img").css("opacity","0.5");
$("#more_image img").css("filter","alpha(opacity=50)");
$("#more_image #more_img1").css("opacity","1");
$("#more_image #more_img1").css("filter","alpha(opacity=100)");


$("#more_img1").attr("src",images_gallery_folder+"img"+real_number+".jpg");
$("#more_img2").attr("src",images_gallery_folder+"img"+real_number+"_1.jpg");
$("#more_img3").attr("src",images_gallery_folder+"img"+real_number+"_2.jpg");
$("#more_img4").attr("src",images_gallery_folder+"img"+real_number+"_3.jpg");
$("#more_img5").attr("src",images_gallery_folder+"img"+real_number+"_4.jpg");



$("#image-code").html($("#code"+total).html());
$("#image-title").text($("#title"+total).text());
$("#image-desc").text($("#desc"+total).text());
$("#image-price").text($("#desc"+total).price());
$("#image-more").html($("#more"+total).html());

$("#short_url").html("http://"+domain+"/product.php?id="+real_number+"&cat="+cat+"&cat_name="+cat_name);
$("#image_page").attr("href","http://"+domain+"/product.php?id="+real_number+"&cat="+cat+"&cat_name="+cat_name);
$.post("update_view.php",{"id":real_number});

$("#face_comment").html('');
$("#social_share").html('');


number=total;


FB.XFBML.parse();
$("#face_comment").load("load_comment.php",{'domain':domain ,'id':real_number},function(){
FB.XFBML.parse();
});
FB.XFBML.parse();
$("#social_share").load("load_social.php",{'domain':domain ,'id':real_number},function(){
FB.XFBML.parse();
});



}
});	


$(".num").click(function(){
xx=parseInt($(this).attr("title"))*400;	
$(".num").css({"background-color":"#aaa"});
$(this).css({"background-color":"#fff"});
$("#image_rows_show").animate({"top":"-"+xx});
});


$('#big-img').mousemove( function(e){
var parentOffset = $(this).parent().offset(); 
//or $(this).offset(); if you really just want the current element's offset
var relX = e.pageX - parentOffset.left;
var relY = e.pageY - parentOffset.top;


pos_x=relX;
pos_y=relY;
$("#mag_big").css({"background":"#fff url('"+ $("#big-img").attr("src") +"')","background-position":"-" + pos_x+"px " +"-" +pos_y+"px"});

//$("#mag_small").css({"left" : relX-15,"top":relY-25});
image_mag="url('"+$("#big-img").attr("src")+"');";
//$("#mag_small").show();
$("#mag_big").show();
});

$('#big-img-div').bind('mouseenter', function(e){
$("#mag_big").hide();
//$("#mag_small").hide();
});


//more_images
$("#more_image img").click(function(){
$("#big-img").attr("src",$(this).attr("src")); 
$("#more_image img").css("opacity","0.5");
$("#more_image img").css("filter","alpha(opacity=50)");

$(this).css("opacity","1");
$(this).css("filter","alpha(opacity=100)");

});


$("#more_results").on("click",function(){

cat=$(this).attr("cat");
num=$(this).attr("num");
start=$(this).attr("start");
search=$(this).attr("search");
page=$(this).attr("page")+".php";
//alert(num);
//alert(page);
$("#load_result").load(page,{"search":search,"cat":cat,"num":num,"start":start},function(){

$("#image_rows_container").append($("#load_result").html());
$("#load_result").html("");

if($("#no_more").text() != ""){ 
new_start=Math.round(((eval($("#more_results").attr("start")))))+Math.round(((eval($("#no_more").text()))));
$("#total").html(new_start);
total=new_start;
$("#more_results").hide() ;
}else{
new_start=parseInt($("#more_results").attr("start"))+parseInt(num);
$("#more_results").attr({"start":new_start});
$("#total").html(new_start);
total=new_start;
}

});	
	
});


$("#more_results_search").on("click",function(){

search=$(this).attr("search");
start=$(this).attr("start");
page=$(this).attr("page")+".php";
//alert(page);
$("#load_result_search").load(page,{"search":search,"start":start},function(){

$("#image_rows_container").append($("#load_result_search").html());
$("#load_result_search").html("");

if($("#no_more").text() != ""){ 

new_start=Math.round(((eval($("#more_results_search").attr("start")))))+Math.round(((eval($("#no_more").text()))));
$("#total").html(new_start);
total=new_start;
$("#more_results_search").hide() ;
}else{
new_start=Math.round(((eval($("#more_results_search").attr("start")))))+24;
$("#more_results_search").attr({"start":new_start});
$("#total").html(new_start);
total=new_start;
}

});	
	
});



$("#wide_show").toggle(function(){
$(".image_thmb_cont").addClass("image_thmb_cont_wide");	

$(".image_thmb_cont").removeClass("image_thmb_cont");	
$(".image_title").addClass("image_title_wide");	
$(".image_title").removeClass("image_title");	
$(".image_code").addClass("image_code_wide");	
$(".image_code").removeClass("image_code");	
$(".image_price").addClass("image_price_wide");	
$(".image_price").removeClass("image_price");	
$(".image_thmb").addClass("image_thmb_wide");	
$(".image_thmb").removeClass("image_thmb");	
$(".image_desc").addClass("image_desc_wide");	
$(".image_desc").removeClass("image_desc");	
},function(){
$(".image_thmb_cont_wide").addClass("image_thmb_cont");	
$(".image_thmb_cont_wide").removeClass("image_thmb_cont_wide");	
$(".image_title_wide").addClass("image_title");	
$(".image_title_wide").removeClass("image_title_wide");	
$(".image_code_wide").addClass("image_code");
$(".image_code_wide").removeClass("image_code_wide");	
$(".image_price_wide").addClass("image_price");	
$(".image_price_wide").removeClass("image_price_wide");	
$(".image_thmb_wide").addClass("image_thmb");	
$(".image_thmb_wide").removeClass("image_thmb_wide");	
$(".image_desc_wide").addClass("image_desc");	
$(".image_desc_wide").removeClass("image_desc_wide");	
	
});


$("#big_show").toggle(function(){
$("#right_body").hide();
$("#left_body").animate({"width":"98%"},0);
$(".image_thmb_cont_wide").animate({"height":"400px"},350);
$(".image_thmb_cont").animate({"height":"400px"},350);
},function(){
$("#right_body").show();
$("#left_body").animate({"width":"77.5%"},0);
$(".image_thmb_cont_wide").animate({"height":"312px"},350);
$(".image_thmb_cont").animate({"height":"312px"},350);	
});



});