$(document).ready(function() {
    //$('#search').attr('value', 'jQuery installiert!');
	
	// to rotate header images 
    initTheRotator();
	// news home page 
	$('#newsSlider').loopedSlider({
		autoStart: 5000
	});	
	$('div#HeaderImagesRotator').fadeIn(1000);
    $('div#HeaderImagesRotator ul li').fadeIn(1000); // tweek for IE
	
	//////////// fancy box for add image and BB
	
	$("#fncy-add-bb").fancybox({
		'width'				: '75%',
		'height'			: '75%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	$("#fncy-add-gallery").fancybox({
		'width'				: '75%',
		'height'			: '50%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});	
	$("a[rel=gallery-images-homepage]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});	
  })
$(document).ready(function() {
//When page loads...
	$(".tab_content_hometabatnumbers").hide(); //Hide all content
	$("ul.tabs_hometabatnumbers li:first").addClass("active").show(); //Activate first tab
	var currentTab_num = $("ul.tabs_hometabatnumbers li:first").find("a").attr("href");
	var currentURL_num = $("ul.tabs_hometabatnumbers li:first").find("a").attr("rel");
	$.get(currentURL_num, function(data){
		$(currentTab_num).html(data).fadeIn("slow");
	});
	$(".tab_content_hometabatnumbers:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs_hometabatnumbers li").click(function() {

		$("ul.tabs_hometabatnumbers li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content_hometabatnumbers").hide(); //Hide all tab content

		var activeTab_num = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		var activeURL_num = $(this).find("a").attr("rel");
		$.get(activeURL_num, function(data){
			$(activeTab_num).html(data).fadeIn("slow");
		});
		return false;
	});
 
///////////// market all 
	  //When page loads...
	  $(".badvmarket").hide(); //Hide all content
	  $("ul.market-tab-list li:first").addClass("selected").show(); //Activate first tab
	  var currentTab_marketall = $("ul.market-tab-list li:first").find("a").attr("href");
	  var currentURL_marketall = $("ul.market-tab-list li:first").find("a").attr("rel");
	  $.get(currentURL_marketall, function(data){
		  $(currentTab_marketall).html(data).fadeIn("slow");
	  });
	  //$(".tab_content:first").show(); //Show first tab content
  
	  //On Click Event
	  $("ul.market-tab-list li").click(function() {
  
		  $("ul.market-tab-list li").removeClass("selected"); //Remove any "active" class
		  $(this).addClass("selected"); //Add "active" class to selected tab
		  $(".badvmarket").hide(); //Hide all tab content
  
		  var activeTab_marketall = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		  var activeURL_marketall = $(this).find("a").attr("rel");
		  $.get(activeURL_marketall, function(data){
			  $(activeTab_marketall).html(data).fadeIn("slow");
		  });
		  return false;
	  });
					 
	
  })  
function addbookmark(){
	var BookmarkURL=location.href  
	var BookmarkTitle=document.title 
	// If the browser is Internet Explorer
	if (document.all)
	{
		  // Add to Favorites (Internet Explorer)
		  window.external.AddFavorite(BookmarkURL,BookmarkTitle)
	}
	else
	{
		  // Add to Bookmarks (Mozilla Firefox)
		  window.sidebar.addPanel(BookmarkTitle, BookmarkURL, '');
	}
}
function AjaxAddComment(){
var http = new XMLHttpRequest();
	var url = "AddComment.php";
	//var params = id;IdScript Script Name Email Comment verif_box
	http.open("GET", url+"?IdScript="+document.ajaxForm.IdScript.value+"&Script="+document.ajaxForm.Script.value+"&Name="+document.ajaxForm.Name.value+"&Email="+document.ajaxForm.Email.value+"&Name="+document.ajaxForm.Name.value+"&Comment="+document.ajaxForm.Comment.value+"&verif_box="+document.ajaxForm.verif_box.value+"", true);
 	http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState<4)
      {
 	 	  document.getElementById("DivaddComment").innerHTML ="<div align='center'><img src='images/loading/loading2.gif' align='absmiddle' /></div>";
		  document.getElementById("DivaddComment").style.display = "block";
      }
		if(http.readyState == 4 && http.status == 200) {
			//alert(http.responseText);
			
			document.getElementById("DivaddComment").innerHTML = http.responseText ;
			document.getElementById("CommentField").style.display = "none" ;
		}
	}
	http.send(null);
}

////////////////// panel slidewhpow ////////////////

var canDo = true;
/** plugin @author: http://www.webinventif.fr/wslide-plugin/ */
$(document).ready(function(){

//           $('#parent1-menu, #parent1, .cube').mouseover(function(){
//                canDo = false;
//            }).mouseout(function(){
//                canDo = true;
//            });
   canDo = true;
	$('#parent1').wslide({
		width: 455,
		height: 220,
		pos: 1,
		//col: 1,
		effect: 'easeOutBounce', //easeOutBounce, easeOutElastic, easeOutExpo
		fade: false,
		horiz: false,
		bland: true,
		//autolink: false,
		speed:300
	});
//setInterval(function() {
//       // Do something every 2 seconds
//}, 2000);

setInterval(function() {
		if(canDo){
			if($('#parent1-menu a:last').hasClass('wactive')){
				$('#parent1-menu a:first').click();
			}else{
				$('#parent1-menu .wactive').next().click();
				//alert("next")
			}
		}
}, 5000);
//            $.timer(1000, function (timer) {
//                if(canDo){
//                    if($('#parent1-menu a:last').hasClass('wactive')){
//                        $('#parent1-menu a:first').click();
//                    }else{
//                        $('#parent1-menu .wactive').next().click();
//						alert("next")
//                    }
//                }
//            });
});
//			$(document).ready(function(){
//				/*====================== Diaporama 360 ======================*/
//				$("#parent1").wslide({
//					width: 390,
//					height: 230,
//					horiz: true,
//					fade: true,
//					duration: 2000,
//					bland: true,
//					autolink: true 
//
//				});
//			});	



 
$(document).ready(function(){
  // Reset Font Size
  var originalFontSize = $('#fontresize').css('font-size');
    $(".resetFont").click(function(){
    $('#fontresize').css('font-size', originalFontSize);
  });
  // Increase Font Size
  $(".increaseFont").click(function(){
	
    var currentFontSize = $('#fontresize').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.2;
	if ( newFontSize < 28 ) {	
    	$('#fontresize').css('font-size', newFontSize);
	}
    return false;
  });
  // Decrease Font Size
  $(".decreaseFont").click(function(){
    var currentFontSize = $('#fontresize').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*0.8;
	if ( newFontSize > 8 ) {	
   		$('#fontresize').css('font-size', newFontSize);
	}
    return false;
  });
});


// market 
var http = new XMLHttpRequest();
function LoadCategoryOptionsSearch(id){
	var url = "modules/market/load_category_options_search.php";
	var params = id;
	http.open("GET", url+"?IdCategory="+document.FrmSearch.IdCategory.value, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState<4)
      {
 	 	  document.getElementById("DivCategoryOptionsSearch").innerHTML ="<div align='center'><img src='images/loading/spinner.gif' align='absmiddle' /></div>";
      }
		if(http.readyState == 4 && http.status == 200) {
			//alert(http.responseText);
			document.getElementById("DivCategoryOptionsSearch").innerHTML = http.responseText ;
		}
	}
	http.send(null);
}
function LoadCategoryOptions(id){
	var url = "modules/market/load_category_options.php";
	var params = id;
	http.open("GET", url+"?IdCategory="+document.FrmAddMarket.IdCategory.value, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState<4)
      {
 	 	  document.getElementById("DivCategoryOptions").innerHTML ="<div align='center'><img src='images/loading/spinner.gif' align='absmiddle' /></div>";
      }
		if(http.readyState == 4 && http.status == 200) {
			//alert(http.responseText);
			document.getElementById("DivCategoryOptions").innerHTML = http.responseText ;
			check_image_limit();
			change_product_title();
		}
	}
	http.send(null);
	
}
function change_product_title(){
	var category_special = document.getElementById("category_special").value;
	//alert(category_special)
	if(category_special == '1'){
		document.getElementById("div_product_title").innerHTML = 'رقم اللوحة / الهاتف'
		//alert('change');	
	}else{
		document.getElementById("div_product_title").innerHTML = 'اسم / عنوان المنتج'	
		//alert('no change')
	}	
}
function check_image_limit(){
	var image_limit_field = document.getElementById("category_limit_image").value;
	//alert(image_limit_field);
	if(image_limit_field == 0 ){
//		document.getElementById("tr_MainImage").style.visibility = "hidden";
//		document.getElementById("tr_gallery_block").style.visibility = "hidden";
		document.getElementById("tr_MainImage").style.display = "none";
		document.getElementById("tr_gallery_block").style.display = "none";
 	}else{
//		document.getElementById("tr_MainImage").style.visibility = "visible";
//		document.getElementById("tr_gallery_block").style.visibility = "visible";
		document.getElementById("tr_MainImage").style.display = "";
		document.getElementById("tr_gallery_block").style.display = "";
  	}
}
function loadlimitimage(id){
	document.getElementById(id).value=5;
} 
