var $j = jQuery.noConflict()
Shadowbox.loadSkin('classic', '/core/js/libs/shadowbox/skin'); // use the "classic" skin
Shadowbox.loadLanguage('en', '/core/js/libs/shadowbox/lang'); // use the English language
Shadowbox.loadPlayer(['img', 'html','iframe','flv'], '/core/js/libs/shadowbox/player'); // use img and qt players

$j(document).ready(function(){
	
	Shadowbox.init({
        // let's skip the automatic setup because we don't have any
        // properly configured link elements on the page
        //skipSetup: true
		resizeLgImages:     true,
        displayNav:         true,
        handleUnsupported:  'remove',
        keysClose:          ['c', 27], // c or esc
        autoplayMovies:     true,
		flvPlayer: '/swf/flvplayer.swf',
		loadingImage: '/images/loading.gif'
    });
	 $j(document).pngFix(); 
});

function init_Shadowbox(){  //For reinitialize if we do Ajax craziness
	
	Shadowbox.setup();
	
	    var options = {
        resizeLgImages:     true,
        displayNav:         true,
        handleUnsupported:  'remove',
        keysClose:          ['c', 27], // c or esc
        autoplayMovies:     true,
		flvPlayer: '/swf/flvplayer.swf',
		loadingImage: '/images/loading.gif'
    };
	//alert('Shadowbox!');
    Shadowbox.init(options);
}


function showProductInfo(product_id){
	 Shadowbox.open({
        player:     'iframe',
        title:      'Product Info',
        content:    '/store/products?action=info&product_id=' + product_id,
        height:     550,
        width:      500
    });
}

function showLightbox(title,url,height,width){
 	Shadowbox.open({
        player:     'iframe',
        title:      title,
        content:    url,
        height:    height,
        width:     width
    });	
}

function estimateShipping(){
	//alert('Shipping');
	country = $F('country');
	zipcode = $F('zipcode');
	if (zipcode == '' && country == 'us'){
		alert('Please enter a valid destination zipcode');	
	}
	else {
		showLightbox('','/store/cart?action=estimate_shipping&country=' + country + '&zipcode=' + zipcode,300,400);
	}
}

function jsConfirm(question,path){
	if (confirm(question)){
			window.location = path;
	}
}

function showDiv(id,speed){
	$j('#'+id).show(speed);
}

function hideDiv(id){
	$j('#'+id).hide('slow');		
}

function fadeInOut(id){
	$j('#'+id).fadeIn('slow');
	$j('#'+id).fadeOut(5000);
}

function toggleDiv(id){
	$j('#'+id).toggle('slow');		
}

function searchBanners(inline){
	if (inline != "false"){
		$j('#results_only').val(true);
	}
	$j.ajax({
			type: "GET",
			url: "banners.php",
			data: $j("#bannersearch_form").serialize(),
			success: function(results) {
					$j("#results").html(results);
			}
	}); 
}

function postForm(my_form,id,value){
	if (setField(id,value)){
		document.getElementById(my_form).submit();	
	}
}



function setField(id,value){
	$j('#'+id).val(value);
	return true;
}


function ajaxRequest(url,output_div){

	$j.ajax({
			type: "GET",
			url: url,
			success: function(results) {
					$j("#" + output_div).html(results);
			}
	});
	//alert('AJAX REQUEST');

}


$j(document).ready(function() {
	findimg();
 });


function findimg()
{
 var imgs,i;
// loop through all images of the document
 imgs=document.getElementsByTagName('img');
 for(i=0;i<imgs.length;i++)
 {
// test if the class 'roll' exists
  if(/roll/.test(imgs[i].className))
  {
// add the function roll to the image onmouseover and onmouseout and send
// the image itself as an object
   imgs[i].onmouseover=function(){roll(this);};
   imgs[i].onmouseout=function(){roll(this);};
  }
 }
}


function roll(o){
 var src,ftype,newsrc;
 // get the src of the image, and find out the file extension
 src = o.src;
 ftype = src.substring(src.lastIndexOf('.'), src.length);
 // check if the src already has an _on and delete it, if that is the case 
 if(/_on/.test(src)){
  newsrc = src.replace('_on','');
  }else{
  // else, add the _on to the src 
  newsrc = src.replace(ftype, '_on'+ftype);
  }
 o.src=newsrc;
}


function shadedBorder(div_id){
	var border = RUZEE.ShadedBorder.create({ corner:8, shadow:16,  border:2 });
	border.render(div_id);	
}

/*
 $j(function(){
       $j("#content").shadow({
           width:5,
           startOpacity:60,
           endOpacity:10,
           cornerHeight:8,
           color:"#000000"
       });
    })
*/
 
 	$j(document).ready(function(){
	$j(".dropshadow")
	.wrap("<div class='wrap0'><div class='wrap1'><div class='wrap2'>" +
	"<div class='wrap3'></div></div></div></div>");
	});
