﻿$(document).ready(function(){
	if ($('#homeFlash').size() > 0) {
        var so = new SWFObject("../flash/copalHome.swf", "copalHome", "800", "365", "8", "#000000");
        so.addParam("wmode", "transparent");
        so.write("homeFlash");
    } else {
        $('a.expand').next().hide();
	    $('a.expand').click(function(){
	        $(this).next().slideToggle();
	    });
    	
        $('.sorted td').hover(function(){
            $(this).parent().addClass("hover");
        },function(){
            $(this).parent().removeClass("hover");
        });
        
        $('.sorted').tablesorter({sortList:[[0,0]]});
        
        $('#filters').find('dd').click(function(){
            $(this).toggleClass('expand').find('.filterOptions').slideToggle('normal', function(){
                shadows();
            });
        });
        $('#filters').find('dd').each(function(){
            $(this).click().toggleClass('expand');
        });
        $('#filters').find('dd > a, .filterOptions > li > a').click(function(){
            document.location.href = $(this).attr('href');
            return false;
        });

		shadows();
		
        if(typeof Shadowbox!="undefined"){
            var options = {
                loadingImage:       '../images/loadingAnimation.gif',
                resizeLgImages:     true,
                flvPlayer:          'flvPlayer.swf',
                handleUnsupported:  'remove',
                keysClose:          ['c', 27] // c or esc
            };
            Shadowbox.init(options);
        }
	}
	
	$('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body')
                .animate({scrollTop: targetOffset}, 500);
                //return false;
            }
        }
    });
	
});

window.onload=function(){
    var ipw = $('#itemPic').find('img').width();
    $('#itemPic').css('width', ipw);
}

function shadows() {
	var mh = $('#main').height();
	$('#sl').html('<img src="/images/shadowLeft.jpg" width="7" alt="" />');
	$('#sr').html('<img src="/images/shadowRight.jpg" width="7" alt="" />');
	$('#sl').css({ height: mh, background: "http://copalart.com/library/url(/images/sl.gif)" });
	$('#sr').css({ height: mh, background: "http://copalart.com/library/url(/images/sr.gif)" });
}

function SetSearch(){
    var query = $('#q').val();
    var url = $('#searchForm').attr('action');
    if(query != ''){
        $('#searchForm').attr({'action': url.replace('[cr]',query.replace(/[^\w\.]/g, '+').replace(/-+/g, '+').replace(/^-/, '').replace(/-$/, '').toLowerCase())});
        return true;
    } else {
        alert('Please provide some search criteria.');
        return false;
    }
}
    
function SubmitForm()
{
    var month = $('#month').val();
    var url = $('#newsLetterForm').attr('action') ;
    if(month != ''){
        $('#newsLetterForm').attr({'action': url.replace('[month]',month)});
        $('#newsLetterForm').submit();
    }
}

function myGallery(mode,itemAlias,galleryAlias){
    $.ajax({
        url: "../login/.4107.html",
        data: "i="+itemAlias+"&g="+galleryAlias+"&mode="+mode,
        type: "POST",
        dataType: "html",
        success: function(data){
            if(mode=='add'){
                if(data > 0)
                    alert("This painting has been added to your personal gallery.");
                else if(data == -1) 
                    alert("This painting is already present in your personal gallery.");
                else if(data == 0) 
                    alert("We encountered an error while adding this paiting to your gallery. Please try again after some time.");
            } else {
                if (data > 0){
                    alert("Successfully Deleted");
                    document.location.href="/mygallery/0/0/0/";
                } else
                    alert("We encountered an error while removing this painting from your gallery. Please try again after some time.");
            }
        }
    });
}

/*

$(document).ready(function(){
	if ($('#homeSlideShow').size() > 0) {
        $('#slides').innerfade({
            speed: 1000,
            timeout: 6000,
            type: 'random_start',
            containerheight: '350px'
        });
    } else {
        $('a.expand').next().hide();
	    $('a.expand').click(function(){
	        $(this).next().slideToggle();
	    });
    	
        $('.sorted td').hover(function(){
            $(this).parent().addClass("hover");
        },function(){
            $(this).parent().removeClass("hover");
        });
        
        $('.sorted').tablesorter({sortList:[[0,0]]});
        
        $('#filters').find('dd').click(function(){
            $(this).toggleClass('expand').find('.filterOptions').slideToggle('normal', function(){
                shadows();
            });
        });
        $('#filters').find('dd').each(function(){
            $(this).click().toggleClass('expand');
        });
        $('#filters').find('dd > a, .filterOptions > li > a').click(function(){
            document.location.href = $(this).attr('href');
            return false;
        });
        
		shadows();
		
        if(typeof Shadowbox!="undefined"){
            var options = {
                loadingImage:       '../images/loadingAnimation.gif',
                resizeLgImages:     true,
                flvPlayer:          'flvPlayer.swf',
                handleUnsupported:  'remove',
                keysClose:          ['c', 27] // c or esc
            };
            Shadowbox.init(options);
        }
	}
	
	$('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body')
                .animate({scrollTop: targetOffset}, 500);
                //return false;
            }
        }
    });
	
});

window.onload=function(){
    var ipw = $('#itemPic').find('img').width();
    $('#itemPic').css('width', ipw);
}

function shadows() {
	var mh = $('#main').height();
	$('#sl').html('<img src="/images/shadowLeft.jpg" width="7" alt="" />');
	$('#sr').html('<img src="/images/shadowRight.jpg" width="7" alt="" />');
	$('#sl').css({ height: mh, background: "http://copalart.com/library/url(/images/sl.gif)" });
	$('#sr').css({ height: mh, background: "http://copalart.com/library/url(/images/sr.gif)" });
}

function SetSearch(){
    var query = $('#q').val();
    var url = $('#searchForm').attr('action');
    if(query != ''){
        $('#searchForm').attr({'action': url.replace('[cr]',query.replace(/[^\w\.]/g, '+').replace(/-+/g, '+').replace(/^-/, '').replace(/-$/, '').toLowerCase())});
        return true;
    } else {
        alert('Please provide some search criteria.');
        return false;
    }
}
    
function SubmitForm()
{
    var month = $('#month').val();
    var url = $('#newsLetterForm').attr('action') ;
    if(month != ''){
        $('#newsLetterForm').attr({'action': url.replace('[month]',month)});
        $('#newsLetterForm').submit();
    }
}

function myGallery(mode,itemAlias,galleryAlias){
    $.ajax({
        url: "../login/.4107.html",
        data: "i="+itemAlias+"&g="+galleryAlias+"&mode="+mode,
        type: "POST",
        dataType: "html",
        success: function(data){
            if(mode=='add'){
                if(data > 0)
                    alert("This painting has been added to your personal gallery.");
                else if(data == -1) 
                    alert("This painting is already present in your personal gallery.");
                else if(data == 0) 
                    alert("We encountered an error while adding this paiting to your gallery. Please try again after some time.");
            } else {
                if (data > 0){
                    alert("Successfully Deleted");
                    document.location.href="/mygallery/0/0/0/";
                } else
                    alert("We encountered an error while removing this painting from your gallery. Please try again after some time.");
            }
        }
    });
}

*/