//Start Config
var peekStoreUrl = "http://www.truelightchristianstore.com/";
var peekAccountNum = "yhst-39560399735444";
var peekOrderBtn = "http://lib.store.yahoo.net/lib/yhst-39560399735444/orderntn.jpg";

jQuery(document).ready(function(){
jQuery('.imagehover img').live("mouseenter",function(){
$('#ProductPop').remove();
var prodImgWidth = $(this).parent().parent().width();
var bgImgOffset = (prodImgWidth - 100)/2;
var prodImgHeight = this.height;
var parentHref = $(this).parent().attr("href");
$('<a>',{
    id: 'ProductPop',
    class: 'sneakpeek',
    href: 'javascript:void(0)',
    rel : $(this).attr("href"),
    style : 'visibility:visible; width:'+prodImgWidth+'px !important; margin-left:'+bgImgOffset+'px !important;',
click: function(e){
e.preventDefault();
$.ajax({ type: "GET",   
         url: parentHref,   
         async: false,
         success : function(returnText)
         {
var startInd = returnText.indexOf("<!--Start True Light Product View") + 33;
var finishInd = returnText.indexOf("End True Light Product View-->");
var jsonStr = returnText.substring(startInd,finishInd);
//var quickData = jQuery.parseJSON(jsonStr);
sneakPeek(jQuery.parseJSON(jsonStr));
}
});
}
}).prependTo($(this).parent().parent());

});



});

//End Config
function sneakPeek(quickData){

$("#sneakpeek").remove();
initTabs(); 

		

//Create SneakPeek Holder
var sneakPeek = $('<div>', {
	id: 'sneakpeek'
}).appendTo("body");
//Insert Item Page Link 
$('<a>', {
	class: 'titlelink',
	href: peekStoreUrl+quickData.id+'.html',
	text: 'View Item Page >>'
}).appendTo(sneakPeek);
//Create Peek Img Div
var peekImg = $('<div>', {
	id: 'peekimg'
}).appendTo(sneakPeek);
//Insert Main Peek Image

var splitMainImg = quickData.image.split("|");
var mainImg = $('<a>', {
	class: 'jqzoom',
	href: splitMainImg[0],
	rel: 'gal'
}).appendTo(peekImg);

$('<img>', {
	src: splitMainImg[1]
}).appendTo(mainImg);
//Create Image Switcher Images
var multiImgUl = $('<ul>', {
	id: "thumblist"
}).appendTo(peekImg);
//Split Mulit Images &
if(quickData.images){
var multiImageSplit = quickData.images.split("&");
//Loop through elements of array and split each and inject into DOM
jQuery.each(multiImageSplit, function(index, indImgs) {
var multiSpitInd = indImgs.split("|");
var multiImgIndLi = $('<li>').appendTo(multiImgUl);
if(index == 0){
var thumbClass = "zoomThumbActive"
}
$('<a>', {
	class: thumbClass,
	href: 'javascript:void(0);',
	rel: '{gallery:\'gal\', smallimage:\''+multiSpitInd[1]+'\',largeimage:\''+multiSpitInd[0]+'\'}',
	html: '<img src='+multiSpitInd[2]+' height="50" width="50" />'
}).appendTo(multiImgIndLi);

});
//End Image Each
}
//Create Tab Menu
var peekTabContain = $('<div>', {
	id: 'tabContainer',
	style: 'width:330px; float:right'
}).appendTo(sneakPeek);
var peekTabMenu = $('<div>', {
	class: 'tabMenu'
}).appendTo(peekTabContain);
var peekTabMenuUl = $('<ul>', {
	class: 'menu'
}).appendTo(peekTabMenu);
var peekTabMenuLi = $('<li>').appendTo(peekTabMenuUl);
$('<a>', {
	class: 'tab_link active',
	href: '#',
	title: '#Tab1-name',
	html: '<span>Details</span>'
}).appendTo(peekTabMenuLi);
//Create Tab Content
var peekTabContent = $('<div>', {
	id: 'tabContent',
	style: 'height:200px'
}).appendTo(peekTabContain);
var peekTabContentDiv = $('<div>', {
	id: 'Tab1-name',
	class: 'content active',
	html: quickData.description
}).appendTo(peekTabContent);
//Create Below Tab Price / Order Area
var peekForm = $('<form>', {
	method: 'post',
id:'orderform',
	action: 'https://order.store.yahoo.net/'+peekAccountNum+'/cgi-bin/wg-order?'+peekAccountNum+'+'+quickData.id}).appendTo(peekTabContain);

var peekBelowTab = $('<div>', {
	id: 'peekcontents',
	class: 'belowtab'
}).appendTo(peekForm);
$('<div>', {
	text: 'Price: '+quickData.price,
	class: 'price'
}).appendTo(peekBelowTab);
if(quickData.sale){
$('<div>', {
	text: 'Sale Price: '+quickData.sale,
	class: 'sale-price'
}).appendTo(peekBelowTab);
jQuery('.price').css("text-decoration","line-through");
}
$('<div>', {
	html: quickData.options,
	class: 'peekOpetions'
}).appendTo(peekBelowTab);
//Create Order Button
var quickPeekOrder = $('<div>', {
	id: 'orderbtn'
}).appendTo(peekForm);
$('<div>', {
	html: 'Qty: <input type="text" size="3" maxlength="3" value="1" name="vwquantity">',
	class: 'quan'
}).appendTo(quickPeekOrder);
$('<input>', {
	src: peekOrderBtn,
	type: 'image',
	title: 'Add to cart',
	id: 'submit',
}).appendTo(quickPeekOrder);
$('<input>', {
	type: 'text',
	value: quickData.ship,
	style: 'visibility:hidden',
	name: 'Ship'
}).appendTo(quickPeekOrder);
$('<input>', {
	type: 'hidden',
	value: quickData.id,
	name: 'vwitem'
}).appendTo(quickPeekOrder);
$('<input>', {
	type: 'hidden',
	value: peekAccountNum,
	name: 'vwcatalog'
}).appendTo(quickPeekOrder);
$('<input>', {
	type: 'hidden',
	value: peekStoreUrl+quickData.id+'.html',
	name: '.autodone'
}).appendTo(quickPeekOrder);


			$('.jqzoom').jqzoom({
            zoomType: 'reverse',
            lens:true,
            preloadImages: false,
            alwaysOn:false,
			zoomWidth:320,
			zoomHeight:320,
			title:false,
        });

		$( "#sneakpeek" ).dialog({
			autoOpen: true,
			resizeable:false,
			width: 700,
			height:400,
			title:quickData.name,
			show:"clip",
			hide:"clip",
modal:true
			
		});
//$("#sneakpeek").dialog( "open" );


}
