
$.fn.center = function(alsdkjfads, oairnvsd){
	if(!alsdkjfads){ var alsdkjfads = '50%'; }
	if(!oairnvsd){ var oairnvsd = '50%'; }
	return this.each(function(){
		$(this).css({
			display: 'block',
			position: 'absolute',
			top: alsdkjfads,
			left: oairnvsd,
			marginTop: -($(this).height() / 2),
			marginLeft: -($(this).width() / 2)
			});
		//alert($(this).css('marginTop'));
		});
	};





$.fn.exists = function() {
	return this.length > 0 ? true : false;
	};
		
// aBox object

var loadimages = function(){
	//alert(loaded[0]+', '+loaded[1]+', '+loaded[2]+', '+loaded[3]+', '+loaded[4]+', '+loaded[5]+', ');
	for(var i in loaded){
		if(loaded[i] !== true){
			return false;
			}
		}
	$('#abox #ab_loading').css({display : 'block'});
	$('#abox img').css({display : 'block'});	
	$('#abox #ab_loading').remove();
	$('#abox img').animate({ opacity: 1 }, 500);
	$('#abox').css('background', 'none');
	};

var loaded = [ false, false, false, false, false, false ];
var ie7 = (navigator.appName == "Microsoft Internet Explorer");
var browseheight;
var first_loaded=0;
var aBox = {
	fadeSpeed : 200,
	expandSpeed : 400,
	loadingImage : 'images/loadingAnimation.gif',
	imageDirectory : 'temp_images/',
	scrollpaneOptions : { scrollbarMargin : 10, showArrows : false, dragMinHeight : 10 },
	isOpen : false,
	isOpening : false,
	
	showBox : function(url, countclick){	
	//alert('second');
	var arrPageSizes = ___getPageSize();
	var arrPageScroll = ___getPageScroll();
	if(ie7)
	browseheight=200;
	else
	browseheight=515;

		if(url=='aLinkAtt')
		{
			/*show the advance search form*/
			//alert(url);
			
			loaded = [ false, false, false, false, false, false ];			
			if(this.isOpening === true || this.isOpen === true){
				return false;
				}
			
				
			this.isOpening = true;			
			if($('#abox').exists()){ $('#abox').remove(); }
			if($('#aboxBlackout').exists()){ $('#abox').remove(); }	
			$('<div></div>').attr('id', 'abox').appendTo('body');
			$('<div></div>').attr('id', 'aboxBlackout').click(function(){ aBox.hideBox(); }).appendTo('body');			
			$('#aboxBlackout').css({ display : 'block', opacity : 0, width: '100%', height : $(document).height(), top : 0, bottom : 0, position: 'absolute' }).animate({ opacity : 0.75 }, this.fadeSpeed, function(){
																																																					
				$('#abox').css({
					height : 2,
					width : 2,
					marginLeft : -1,
					marginTop : -1,
					display : 'block',
					opacity : 1,
					zIndex : 10000
					})
				.animate({ //changed for adjusting IE issue 
				height : browseheight,
				marginTop : -252
				
				}, this.expandSpeed)
			.animate({
				width : 600,
				//marginLeft : -285 tis is the advance search box
				marginLeft : -300
					}, this.expandSpeed, function(){
						var loadFrom = $('div.aSearch');			
						
						$('<img>').addClass('st_close').css({ display: 'block', opacity: 1, zIndex: 50 }).attr('src', 'images/st_close.png').click(function(){ aBox.hideBox(); }).appendTo('#abox');						
						//loadFrom.css({ display: 'block', opacity: 1, zIndex: 50 });
						$('#abox').append(loadFrom.html());
						
						aBox.isOpening = false;
						aBox.isOpen = true;
						}
					);
				});
			
			//exit;
		}
		loaded = [ false, false, false, false, false, false ];
		if(!countclick){ countclick = false; }
		if(this.isOpening === true || this.isOpen === true){
			return false;
			}
		this.isOpening = true;
		
		jcl_restart = false;
		if(!jcl_stoplock){
			jcl_restart = true;
			}
		$('input.scr_pause').css('backgroundImage', 'url(images/scr_play.png)');
		jcl_int = clearInterval(jcl_int);
		jcl_stopped = true;
		jcl_stoplock = true;
		
		if($('#abox').exists()){ $('#abox').remove(); }
		if($('#aboxBlackout').exists()){ $('#abox').remove();  }

		$('<div></div>').attr('id', 'abox').appendTo('body');
		$('<div></div>').attr('id', 'aboxBlackout').click(function(){ aBox.hideBox(); }).appendTo('body');
		
		$('#aboxBlackout').css({ display : 'block', opacity : 0, width: '100%', height : $(document).height(), top : 0, bottom : 0, position: 'absolute' }).animate({ opacity : 0.75 }, this.fadeSpeed, function(){
			$('#abox').css({
				height : 2,
				width : 2,
				marginLeft : -1,
				marginTop : -1,
				display : 'block',
				opacity : 1,
				zIndex : 10000
				})
			.animate({
				height : 515,
				/*marginTop : -252*/
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10)
				}, this.expandSpeed)
			.animate({
				width : 770,
				marginLeft : -385
				}, this.expandSpeed, function(){					
					$('<img>').attr({ id : 'ab_loading', src : aBox.loadingImage }).css({
						display: 'block',
						opacity: 1
						}).load(function(){ $(this).center(false, 225); }).appendTo('#abox');
					
					$('<img>').addClass('st_close').css({ display: 'block', opacity: 1, zIndex: 50 }).attr('src', 'images/st_close.png').click(function(){ aBox.hideBox(); }).appendTo('#abox');
					//alert($("lsls").exists());
					//alert(document.getElementById('storePopUpsDiv').innerHTML);
					//alert(url);
					//alert($('div.storePopup[storeid=' + url + ']').exists());
					//alert($('div.storePopup[storeid=' + url + ']').html());
					if(!$('div.storePopup[storeid=' + url + ']').exists()){				
					
					//alert($('div.storePopup[storeid=' + url + ']').html());
						$('#abox').append($('<p></p>').addClass('loadError').html('Sorry, the storefront could not be loaded.'));
						}
					else{
						apndStr = "";
						if($.browser.msie){
							apndStr = 1*new Date();
							}
						var loadFrom = $('div.storePopup[storeid=' + url + ']');
						var loadFromDetail = $('div.st_detail[storeid=' + url + ']');
					
						$('#abox').append(loadFrom.html());
						$('#abox .st_description').jScrollPane(aBox.scrollpaneOptions);
						if ($.browser.msie) {
							this.style.removeAttribute('filter');
							}
						$('#abox img.st_logo').load(function(){
							$(this).css({
								marginRight : -($(this).width() / 2),
								marginTop : -($(this).height() / 2)
								});
							});
						/*show the image of submit button*/	
						$('<img>').attr({ src: 'images/button_visit_store_o.png' }).css({ position: 'absolute', left: -10000 });
						
						$('#abox .st_visit').css({ display: 'block', opacity: 1 }).mouseover(function(){ $(this).attr({ src: 'images/button_visit_store_o.png' }); }).mouseout(function(){ $(this).attr({ src: 'images/button_visit_store.png' }) }).wrap(document.createElement('a'));
						
						$('#abox .st_visit').parent().attr('href', 'online.php?store_id=' + loadFrom.attr('storename').replace(/[^a-zA-Z0-9',_\ -]/, '-'));
						/*show the image of logo on perticular store*/	
						$('#abox .st_logo').attr('src', 'wp-content/uploads/logo_images/med/' + loadFrom.attr('img_logo')).one('load', function(){ loaded[4] = true; loadimages(); });
						/*show the image of arcade front(large image) on perticular store*/
						$('#abox .st_largeimage').attr('src', '' + loadFrom.attr('img_11')).one('load', function(){ loaded[5] = true; loadimages(); });
						
						//alert(loadFrom.attr('img_1'));
						
						/*show the small-1 image for category on perticular store*/	
						//alert(loadFrom.attr('img_1'));
					
						//$.preloadImages();
						//alert(loadFrom.attr('img_1')+loadFrom.attr('img_2')+loadFrom.attr('img_3')+loadFrom.attr('img_4'));
					//$.preloadImages(loadFrom.attr('img_1'),loadFrom.attr('img_2'),loadFrom.attr('img_2'),loadFrom.attr('img_3'),loadFrom.attr('img_4'));
						
						if(loadFrom.attr('img_1')!=undefined)
						{
							$('#abox .st_smallimage:eq(0)').attr('src', '' + loadFrom.attr('img_1')).one('load', function(){ loaded[0] = true; loadimages(); });
							
							//$('#abox .st_smallimage:eq(0)').attr('large', '' + loadFrom.attr('img_11')).one('load', function(){ loaded[0] = true; loadimages(); });
						}
						/*show the small-2 image for category on perticular store*/	
						if(loadFrom.attr('img_2')!=undefined)
						{
							$('#abox .st_smallimage:eq(1)').attr('src', '' + loadFrom.attr('img_2')).one('load', function(){ loaded[1] = true; loadimages(); });
						//		$('#abox .st_smallimage:eq(1)').attr('large', '' + loadFrom.attr('img_22')).one('load', function(){ loaded[0] = true; loadimages(); });
						}
						/*show the small-3 image for category on perticular store*/	
						if(loadFrom.attr('img_3')!=undefined)
						{
							$('#abox .st_smallimage:eq(2)').attr('src', '' + loadFrom.attr('img_3')).one('load', function(){ loaded[2] = true; loadimages(); });
							
						//	$('#abox .st_smallimage:eq(2)').attr('large', '' + loadFrom.attr('img_33')).one('load', function(){ loaded[2] = true; loadimages(); });
						}
						
						/*show the small-4 image for category on perticular store*/	
						if(loadFrom.attr('img_4')!=undefined)
						{
							$('#abox .st_smallimage:eq(3)').attr('src', '' + loadFrom.attr('img_4')).one('load', function(){ loaded[3] = true; loadimages(); });
							//alert(loadFrom.attr('img_44'));
						//	$('#abox .st_smallimage:eq(3)').attr('large', '' + loadFrom.attr('img_44')).one('load', function(){ loaded[3] = true; loadimages(); });
						}		
						$.preloadImages(loadFrom.attr('img_11'),loadFrom.attr('img_22'),loadFrom.attr('img_33'),loadFrom.attr('img_44'));
		
						
						
						/*show the description of small image on mouse over*/	
						if(loadFromDetail.attr('detail_1')!=undefined)						
							$('#abox .st_smallimage:eq(0)').attr('html',loadFromDetail.attr('detail_1'));
						if(loadFromDetail.attr('detail_2')!=undefined)	
							$('#abox .st_smallimage:eq(1)').attr('html',loadFromDetail.attr('detail_2'));
						if(loadFromDetail.attr('detail_3')!=undefined)	
							$('#abox .st_smallimage:eq(2)').attr('html',loadFromDetail.attr('detail_3'));
						if(loadFromDetail.attr('detail_4')!=undefined)
							$('#abox .st_smallimage:eq(3)').attr('html',loadFromDetail.attr('detail_4'));					
						
						//alert(loadFromDetail.attr('detail_1'));
						
						/*By default show the description of small image-1 on mouse over*/
						$('#abox .st_detail').html(loadFromDetail.attr('detail_1'));						
						
						$('#abox img').css({ opacity: 0 });
						$('#abox #ab_loading, #abox img.st_close, #abox img.st_visit').css({ opacity: 1 });
						
						$('#abox a.ab_ajax')
						.bind('success', function(){
							alert($(this).attr('success'));
							})
						.bind('error', function(){
							$('#abox').children().fadeOut();
							$('#abox .st_visit').fadeOut();
														
							var regnow = $('<div></div>')
							.attr('id', 'ab_regnow')
							.css({
								display: 'block',
								opacity: 0,
								position: 'absolute',
								top: '50%',
								left: '50%',
								height: 0,
								width: 0,
								backgroundColor: '#ffffff',
								zIndex: 100001,
								border: '1px solid #000000',
								padding: 5
								})
							.appendTo('#abox')
							.animate({
								opacity: 1,
								height: 70,
								width: 260,
								marginLeft: -130,
								marginTop: -35
							}, 500, function(){
								$(this).html('<p>Register Now to enter Sign in and Win, bookmark favourites and receive e-news updates of new stores, destinations and special offers.</p><p style="margin-top: 5px;"><a href="/dev/login">Click here to enter</a> / <a href="#" id="ab_msg_close">Close this window</a></p>');
							
								$('#ab_msg_close').click(function(){
															  
									$('#ab_regnow').empty()
									.animate({ opacity: 0, height: 0, width: 0, marginLeft: 0, marginTop: 0 }, 500, function(){
										$(this).remove();
										});
									$('#abox').children().fadeIn();
									$('#abox .st_visit').fadeIn();
									return false;
									});
								});
							
							});
					
						if($('#abox .st_smallimage:eq(0)').attr('large')==""){
					$('#abox .st_smallimage:eq(0)').attr('large', '' + loadFrom.attr('img_11'));
						}
						
						
						
						//if($('#abox .st_smallimage:eq(0)').attr('src')!=""){
							//alert('sls');
							//	alert('first omage loaded');
							for(i=1;i<4;i++){
									if(($('#abox .st_smallimage:eq('+i+')').attr('large'))==""){
									$('#abox .st_smallimage:eq('+i+')').attr('large', '' + loadFrom.attr('img_'+(i+1)+''+(i+1))).one('load', function(){ loaded[i] = true; loadimages(); });
									$('#abox .st_smallimage:eq('+i+')').attr('largepath', '' + loadFrom.attr('image_path'+(i+1)+''+(i+1))).one('load', function(){ loaded[i] = true; loadimages(); });														
								}
							}
							
						//}
						var imgpreload=new Image();
						$('#abox .st_smallimage:eq(0)').attr('large', '' + loadFrom.attr('img_11')).one('load', function(){ loaded[5] = true; loadimages(); });
						
								
					imgpreload.src=$('#abox .st_smallimage:eq(1)').attr('large');
						$('#abox img.st_largeimage').attr('src',$('#abox .st_smallimage:eq(1)').attr('large')).one('load', function(){ loaded[5] = true; loadimages(); });					
						
						imgpreload.src=$('#abox .st_smallimage:eq(2)').attr('large');
						$('#abox img.st_largeimage').attr('src',$('#abox .st_smallimage:eq(2)').attr('large')).one('load', function(){ loaded[5] = true; loadimages(); });					
						
						imgpreload.src=$('#abox .st_smallimage:eq(3)').attr('large');
						$('#abox img.st_largeimage').attr('src',$('#abox .st_smallimage:eq(3)').attr('large')).one('load', function(){ loaded[5] = true; loadimages(); });					
						
						
						imgpreload.src=$('#abox .st_smallimage:eq(0)').attr('large');
						$('#abox img.st_largeimage').attr('src',$('#abox .st_smallimage:eq(0)').attr('large')).one('load', function(){ loaded[5] = true; loadimages(); });
						//alert(first_loaded);
						$('#abox img.st_smallimage').mouseover(function(){
				
							var l_src = $('#abox img.st_largeimage').attr('src');	
							
							if($(this).attr('largepath')!=""){
							$('#abox img.st_largeimage').attr('src', $(this).attr('largepath')+'/large/'+$(this).attr('large'));							
							}
							else {
							$('#abox img.st_largeimage').attr('src',$(this).attr('large'));							
	
							}
							
							$('#abox div.st_detail').html($(this).attr('html'));							
							});
						}
						
					/*if($("#abox div.st_detail").load){
						
					//alert('abox loaded');	
						for(i=1;i<4;i++){
									
							//alert(loadFrom.attr('image_path'+(i+1)+''+(i+1))+'/large/'+loadFrom.attr('img_'+(i+1)+''+(i+1)));
							imgpreload.src=loadFrom.attr('image_path'+(i+1)+''+(i+1))+'/large/'+loadFrom.attr('img_'+(i+1)+''+(i+1));
							//alert(imgpreload.src);
									
						}
					}*/
					
					imgpreload.src=loadFrom.attr('image_path'+(1+1)+''+(1+1))+'/large/'+loadFrom.attr('img_'+(1+1)+''+(1+1));
						//alert(imgpreload.src);
						imgpreload.src=loadFrom.attr('image_path'+(2+1)+''+(2+1))+'/large/'+loadFrom.attr('img_'+(2+1)+''+(2+1));
						//alert(imgpreload.src);
						imgpreload.src=loadFrom.attr('image_path'+(3+1)+''+(3+1))+'/large/'+loadFrom.attr('img_'+(3+1)+''+(3+1));
						//alert(imgpreload.src);

					// aBox.loadPageData(url);
					//alert(countclick);
					//if(countclick){
					//	$.getJSON('/ajax_update_views.php?store=' + loadFrom.attr('storeid'), function(data){ if(data.error !== 'success'){ alert(data.error); } });
					//	}

					aBox.isOpening = false;
					aBox.isOpen = true;
					
					}
				);
			});
		},
	
	hideBox : function(){
		if(this.isOpen === false || this.isOpening === true){
			return false;
		
			}
		
		$('#abox').empty();
			$('#abox').css('background', '#ffffff');
		//$('#abox').animate({background : '#ffffff' }, 500, function(){
			$('#abox').animate({
				width : 2,
				marginLeft : -1
				}, this.expandSpeed)
			.animate({
				height : 2,
				marginTop : -1
				}, this.expandSpeed, function(){
					$(this).css({ display : 'none' });
					$('#aboxBlackout').animate({ opacity : 0 }, this.fadeSpeed, function(){
						$(this).css({ display : 'none' });
						aBox.isOpen = false;
						aBox.isOpening = false;
						//alert(aBox.isOpen);
						//mohnish added 21-12-09
						if($("#sc_frame").exists()){
							//alert('sds');	
							document.getElementById('sc_frame').style.zIndex='999999';
							}
							
						if(jcl_restart){
							$('input.scr_pause').css('backgroundImage', 'url(images/scr_pause.png)');
							go(jcl_dir == 'left' ? curr-1 : curr+1);
							jcl_int = setInterval(function() { go(jcl_dir == 'left' ? curr-1 : curr+1); }, 4000);
							jcl_stopped = false;
							jcl_stoplock = false;
							}
						});
					}
				);
			//});
		},
	
	loadPageData : function(urlRequest){
		/*
		$.getJSON(urlRequest, function(data){
			// remove loading animation
			
			// create close button
			$('<img>').addClass('st_close').attr('src', 'images/st_close.png').click(function(){ aBox.hideBox(); }).appendTo('#abox');
			
			// create large image
			$('<img>').attr({ id : 'st_largeimage', src : aBox.imageDirectory + data.images.storefront }).appendTo('#abox');
			
			// create logo
			$('<img>').attr({ id : 'st_logo', src : aBox.imageDirectory + data.images.logo }).appendTo('#abox');
			
			// description box
			$('<div></div>').attr({ id : 'st_description' }).html(data.description).appendTo('#abox').jScrollPane();
			//$('#abox').append('<pre>' + getProps(data, 'data') + '</pre>');
			});
		*/
		}
	};


function ___getPageScroll() {
			var xScroll, yScroll;
			if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};


function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};







	// init aBox when form load or ready
$(function(){
		  
	if($.browser.msie){
		
		$('[abox]')
		.mouseover(function(){ $(this).css('cursor', 'pointer'); })
		.mouseout(function(){ $(this).css('cursor', 'default'); })
		.click(function(){/*when click on image it show the popup for store*/
						
						var tmp=$(this).attr('storeid');
						$.get("popup-store-divs.php",{ storeid: $(this).attr('storeid'),scrollNum: $(this).attr('scrollNum')}, function(data){
				 		document.getElementById('storePopUpsDiv').innerHTML += data;
						//alert(document.getElementById('storePopUpsDiv').innerHTML);
							aBox.showBox(tmp, $(this).attr('abox') == 'count' ? true : false);
						//alert(document.getElementById('storePopUpsDiv').innerHTML);
					});
						
		
			return false;
			});
		
		$('[advanceLink]')
		.mouseover(function(){ $(this).css('cursor', 'pointer'); })
		.mouseout(function(){ $(this).css('cursor', 'default'); })
		.click(function(){	/*when click on advance link it show the popup for advance search form*/			
			//alert("hi");
			aBox.showBox($(this).attr('aLinkAtt'));
			return false;
			});		
		}
	else{
		
		var load = new Image();
		load.onload = function(){/*when click on image it show the popup for store*/
			$('[abox]')
			.mouseover(function(){ $(this).css('cursor', 'pointer'); })
			.mouseout(function(){ $(this).css('cursor', 'default'); })
			.click(function(){
						//alert('first');
			//	if(!document.getElementById($(this).attr('storeid'))){
				//	alert('ksk1');
				var tmp=$(this).attr('storeid');
				
				$.get("popup-store-divs.php",{ storeid: $(this).attr('storeid'),scrollNum: $(this).attr('scrollNum')}, function(data){
				 		document.getElementById('storePopUpsDiv').innerHTML = data;
						//alert(document.getElementById('storePopUpsDiv').innerHTML);
						
						//alert(document.getElementById('storePopUpsDiv').innerHTML);
						aBox.showBox(tmp, $(this).attr('abox') == 'count' ? true : false);
					});
			//	}
				//alert('ll');
				
				return false;
				});
			
			$('[advanceLink]')
			.mouseover(function(){ $(this).css('cursor', 'pointer'); })
			.mouseout(function(){ $(this).css('cursor', 'default'); })
			.click(function(){
							//mohnish added 21-12-09
							if($("#sc_frame").exists()){
							//alert('sds');	
							document.getElementById('sc_frame').style.zIndex='-99';
							}
							//else
							//alert('jjj');
							
							/*alert(document.getElementById('sc_frame').style.zIndex);
	document.getElementById('sc_frame').style.zIndex='';*/
							/*when click on advance link it show the popup for advance search form*/		
				//alert("hi");
				
			//	$.get("test.php", function(data){
  
 // div.innerHTML = data;
 // aBox.showBox($(this).attr('aLinkAtt'));
//});
/*
				$.get("test.php",{ storeid: $(this).attr('storeid'),count: $(this).attr('count')}, function(data){
				  alert("Data Loaded: " + data);
				});
				*/


			aBox.showBox($(this).attr('aLinkAtt'));
			return false;
			});
			};
		load.src = aBox.loadingImage;
		}
	});
	

