
/* justin alexander ######### */
/* Güneş Eser - guneseser.com */

var localhost = "/sincerity/JustinAlexanderBridal.com";
var localhost = '';
var ajaxurl = "http://"+document.domain+localhost+"/include/ajax_functions.php";

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('.tooltipBig').css('display', 'none');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('display', 'none');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

document.onclick = jsddm_close;

$(document).ready(function () {
	 $("#newsletterLink").colorbox({iframe:true, innerWidth:610, innerHeight:600,bottom:0,scrolling:true}); 
	/*$("#newsletterLink").colorbox(
			{iframe:true,			
			innerWidth:0,			
			innerHeight:0,			
			scrolling:false,			
			onComplete:function(){			
			$.colorbox.resize(			
			{			
			innerHeight:($('iframe').offset().top + $('iframe').height()),			
			innerWidth:($('iframe').offset().left + $('iframe').width())			
			}			
			);			
			}			
			}			
		);*/
	$('.sendItem').bind('mouseover', jsddm_open);
    $('.tooltipBig').bind('mouseout',  jsddm_timer);
   
	$(".JAbutton").hover(function(){
		$(this).addClass('current');
	});
	$(".JAbutton").mouseout(function(){
		$(this).removeClass('current');
	});
	
    $('input#txtSearch').focus(function () { $(this).val(''); });

//    $('#section').css('min-height', $(document).height() - 248);
/*
    $(window).resize(function () {
        $('#section').css('min-height', $(document).height() - 248);
    });
*/
    $('a.roll').hover(function () {
        $(this).parent().siblings().children('.littleStar').fadeOut();
        $(this).parent().siblings().children('.littleNav').fadeOut();
        $(this).siblings('.littleStar').fadeIn();
        $(this).siblings('.littleNav').fadeIn();
    });

    $('a.roll').hover(function () {
        $(this).parent().siblings().children('.littleInfoAlter').fadeOut();
        $(this).siblings('.littleInfoAlter').fadeIn();
    });

    $('.addFav').toggle(function () { addRemoveFav('addFav','addFavOk');	},   function () { 	addRemoveFav('addFav','addFavOk');	});
	

    $('.addFavLittle').toggle(function ()  { addRemoveFavObj('addFavLittle','addFavLittleOk',$(this));	},   function () { 	addRemoveFavObj('addFavLittle','addFavLittleOk',$(this));	});
	
//	{ $(this).addClass('addFavLittleOk'); },   function () { $(this).removeClass('addFavLittleOk'); });

    $('#pageSlideLeft').click(function () { $('#pageSlideLeftBottom').click(); });
    $('#pageSlideRight').click(function () { $('#pageSlideRightBottom').click(); });
	
	$(".sendItem").mouseenter(function(){
    $('.tooltipBig').fadeIn(); 
  	});

  	$(".tooltipBig").mouseleave(function(){
  		$('.tooltipBig').fadeOut(); 
  	});
   
	$('body').click(function () { 
		$('.tooltipBig').fadeOut();
	 });
	 $('.popupStore .close').click(function () { 
		$('.popupStore').fadeOut();
	 });

    $('.sendPress').hover(function () { $(this).siblings('.tooltipBig').fadeIn(); });
    /*     $("#pageSlider").mouseout(function () {  */
    /*         $('.littleInfo').fadeOut();          */
    /*     });                                      */
	
		pageurl = $(location).attr('href').toLowerCase();
		var p = strpos(pageurl,'start=',0);
		if(p!==false){
			var arrPage = parse_url(pageurl);			
			var findArr = explode('&',arrPage.query);
			var params = new Array();
			for(i=0;i<findArr.length;i++){
				temp = explode('=',findArr[i]);
				if(temp[0] != 'start'){
					params += temp[0]+'='+temp[1];	
				}
			}
			urlArr = explode('?',pageurl);
			final = urlArr[0]+'?'+params;
			pageurl = final;			
		}
	if(!pageurl) {
		pageurl = 'index.php';
	}
	$('#nav li a').each(function(){
		var href = $(this).attr('href').toLowerCase();
		//alert(href+'--------------------'+pageurl);
		if ( (href == pageurl) || (href == '') ) {
			$(this).addClass('current');
		} else {
			$(this).removeClass('current');
		}
	});

});


$.tools.tabs.addEffect("fader", function (tabIndex, done) {

    var conf = this.getConf(), speed = conf.fadeOutSpeed, panes = this.getPanes();
    var $tab = this.getCurrentTab();
    panes.fadeOut(400, done);
    panes.eq(tabIndex).fadeIn(400, done);
    $tab = this.getTabs().eq(tabIndex);
    done.call();

});
function initIds(id,entity_id){
	$("#proid").val(id);
	$("#entity_id").val(entity_id)	;
}
function addRemoveFav(fav,favok){
	var data = {
		action: "addfav",
		id : $("#proid").val(),
		entity_id:$("#entity_id").val()
	};
	if($("."+favok).length > 0){
		data.action = 'removefav';		
	}
	$.post(ajaxurl,data,function(response){		
		//Add case no_user redirect login page
		if(response == 'no_user') {
			var goto = "http://"+document.domain+localhost+"/login.php";	
			goToURL(goto);
		}else{
		alert(response);
		if($("."+favok).length > 0){
			$("."+fav).removeClass(favok);
		}else{
			$("."+fav).addClass(favok);
		}
		}
	});
	
}

function addRemoveFavObj(fav,favok,obj){
	var data = {
		action: "addfav",
		id : $("#proid").val(),
		entity_id:$("#entity_id").val()
	};
	if(obj.hasClass(favok)){
		data.action = 'removefav';		
	}
	$.post(ajaxurl,data,function(response){
		if(response == 'no_user') {
			var goto = "http://"+document.domain+localhost+"/login.php";	
			goToURL(goto);
		}else{
		alert(response);
		if(obj.hasClass(favok)){
			obj.removeClass(favok);
		}else{
			obj.addClass(favok);
		}
		}
	});
	
}

function getRetailerData(i,jid){
	$('.popupStore').fadeOut();
	$("#ad"+i+" .popupStore").fadeIn();
	/*var data = {
		action: "get_retailer",
		retailer:true,
		jid : jid		
	};
	$.post(ajaxurl,data, function(response) {
   			console.debug(response);
			$('.popupStore').hide();
			 $("#ad"+i+" .popupStore").show();
//			 $("#ad"+i+" .popupStore").colorbox({ open: true });	
  	});*/ 
	
}

function goToURL(url){
	window.location=url;	
}
