﻿/// <reference path="jquery-1.4.4.min.js" />
$(document).ready(function () {

	var app_url = $('.app-domain').val();
	var appFullPath = $('.app-url').val();

	//add magnifying glass to each book item in the list
	var imagePath = $('.hd-image-path').val();

	$('.btn-magnifier').attr("src", imagePath + 'icon_magnifier.jpg');

	$('.btn-magnifier').click(function () {
		var imageName = $(this).siblings('.img-url').val();
		if (imageName.indexOf("http://") == -1)
			ProductViewUtils.OpenImagePopup("http://" + appFullPath + "/imageviewer.aspx?img=http://" + app_url + imageName);
		else
			ProductViewUtils.OpenImagePopup("http://" + appFullPath + "/imageviewer.aspx?img=" + imageName);

		return false;
	});

	$('.lnk-view-img').click(function () {
		var imageName = $(this).siblings('.img-url').val();
		if (imageName.indexOf("http://") == -1)
			ProductViewUtils.OpenImagePopup("http://" + appFullPath + "/imageviewer.aspx?img=http://" + app_url + imageName);
		else
			ProductViewUtils.OpenImagePopup("http://" + appFullPath + "/imageviewer.aspx?img=" + imageName);

		return false;
	});

	//binding add to basket images
	$('.btn-add-to-basket').each(function () {
		$(this).attr("src", imagePath + 'addtobasket_New.jpg');
	});

	//binding click to book image to show book details
	$('.book-image').click(function (event) {

		event.preventDefault();

		var imgName = $(this).siblings('.img-url').val();
		var docId = $(this).siblings('.doc-id').val();

		var imgUrl = "";

		if (imgName.indexOf("http://") == -1) {
			imgUrl = "http://" + app_url + imgName;
		}
		else {
			imgUrl = imgName;
		}
		var detailPageUrl = "http://" + appFullPath + "/bookdescription.aspx?docid=" + docId + "&img=" + imgUrl;
		ProductViewUtils.PopupDescription(detailPageUrl);
	});

	//bind click handler to book title link button
	$('.lnk-book-title').click(function (event) {
		event.preventDefault();

		var imgName = $(this).prev().find('.img-url').val();
		var docId = $(this).prev().find('.doc-id').val();

		var imgUrl = "";

		if (imgName.indexOf("http://") == -1) {
			imgUrl = "http://" + app_url + imgName;
		}
		else {
			imgUrl = imgName;
		}
		var detailPageUrl = "http://" + appFullPath + "/bookdescription.aspx?docid=" + docId + "&img=" + imgUrl;
		ProductViewUtils.PopupDescription(detailPageUrl);

	});
});

var ProductViewUtils = {
	OpenImagePopup : function (url) {
		var url = url
		var win = 'toolbar=0,directories=0,menubar=0,scrollbars=1,resizable=0,width=540,height=540';
		window.open(url, '', win, '');
	},
	
	PopupDescription : function(url) {
		var url = url;
		var win = 'toolbar=0,directories=0,menubar=0,scrollbars=1,resizable=1,width=750,height=550';
		window.open(url, '', win, '');
	}
};


