$(document).ready(function(){
	
	startList();
	
	if (typeof shadowbox_init == "function") {
		shadowbox_init();
	}
	
	if (typeof shadowbox_products_init == "function") {
		shadowbox_products_init();
	}
	
	if (typeof sIFR == "function") {
		sIFR.replaceElement("#mainHeading", named({sFlashSrc: "/assets/swf/optima.swf", sColor: "#CCCCCC", sCase: "upper", sBgColor: "#0C0C0C", sWmode: "transparent"}));
		sIFR.replaceElement(".subHeading", named({sFlashSrc: "/assets/swf/optima.swf", sColor: "#CCCCCC", sBgColor: "#0C0C0C", sWmode: "transparent"}));
	}
	
});

function get(el) {
    if($(el).length > 0) {
        return true;
    }
}


function startList() {
	if (document.all && document.getElementById) {
		$('.menuItem').hover(function(){
			$(this).addClass('over');
	     }, function() {
			$(this).removeClass('over');
	    }).click(function(){
			window.location = $(this).children('a').attr('href');
	    });
	}
}

///////// For the gallery pages
var cImgId = -1
var addClicked = false;

function updateBasket(data) {
	
	addClicked = false;
	infoArr = String(data).split(",");
	$('#basketCount').text(infoArr[0]);
	$('#basketTotal').text(infoArr[1]);
	
}

function submit_addToBasket() {
	
	var selected_format = $('#addbasket-photoformat option:selected');
	if (!addClicked) {
		if(selected_format.val() != "") {
			
			formvars = $('#addtobasket').serialize();
			$.post("/shop/add_to_basket", { id: cImgId, formvars: formvars }, updateBasket);
			addClicked = true;
			
			
		} else {
			
			alert("You haven't selected a format for the photo!");
			
		}
	}
	
	return false;
	
}

function updatePhotoFormats(data) {
	
	$('#lightbox-addToBasket input[type="submit"]').removeAttr('disabled');
	$('#addbasket-photoformat').html('<option value="" selected="selected">Choose a format</option>');
	$('#addbasket-photoformat').append(data);
	
}

function set_img_id() {
	var cImg = Shadowbox.getCurrent();
	cImgId = String(cImg.el.id).substring(1);
}

function lightbox_open() {
	
	set_img_id();
	$('#lightbox-addToBasket').css({ 'display' : 'block' });
	$('#addbasket-photoformat').css({ 'visibility' : 'visible' });
	
}

function lightbox_change(newImgId) {
	
	set_img_id();
	$('#lightbox-addToBasket input[type="submit"]').attr('disabled', 'disabled');
	
}

function lightbox_finish() {
	
	$.post("/shop/photo_formats_by_id", { id: cImgId }, updatePhotoFormats);
	$('#addbasket-photoformat').css({ 'visibility' : 'visible' });
	
}

function lightbox_close() {
	$('#lightbox-addToBasket').css({ 'display' : 'none' });	
}

