$(document).ready(function(){
/* Promjena standardnih funkcija ********************************************************************************************************/

    //openImagePopup  
    $("img").filter(function(){return $(this).attr('onclick'); }).each(function() {   
        var attrValue = $(this).attr("onclick");
	    if($.browser.mozilla) { var re = new RegExp("\"(.*?)\""); } else { var re = new RegExp("'(.*?)'"); }
	    var attrUri = re.exec(attrValue);  
	    if (attrUri != null || $(this).hasClass('will_print') ) {
	        $(this).removeAttr("onclick").wrap("<a class='printme nob' href='" + URL_prefix + attrUri[1] + "' title='Zoom'></a>");
	    } else if (attrUri != null){
	        $(this).removeAttr("onclick").wrap("<a class='zoom nob' href='" + URL_prefix + attrUri[1] + "' title='Zoom'></a>");
	    }
    });
    //otvori_prozor
    $("a[href^='javascript:otvori_prozor']").each(function() {
        var hrefVal = $(this).attr("href");
        var reL = new RegExp("[0-9]+");
        var hrefUri = reL.exec(hrefVal);
        if (hrefUri != null) {
            $(this).removeAttr("href").attr("href",URL_prefix + "Home.aspx?PageID=" + hrefUri).addClass("frame");
        }
    });
    function openImagePopup() {
        return false;
    }
    //target:_top kao modalni prozor
    $("a[target^='_top']").each(function() {
        $(this).removeAttr("target").addClass("frame");
    });
    //appends, wraps and befores
	$('#nav-wrapper').append("<div id='nav-l'></div><div id='nav-r'></div");
	//required fields
	if ($('.info-label span').hasClass('error') ) {
        $('.required').each(function(){
            if ($(this).children('input').val() == '') {
                $(this).children('input').addClass('error');
            }
        });  
    }

/* Incijalizacija plugin funkcija ******************************************************************************************************/
    //i can has some cycled content
	$('body#home #quotes, body#home #head').cycle({fx:'fade',speed:1000,timeout:5000,cleartype:true,cleartypeNoBg:true});
	//modals
	$('.zoom, .printme').fancybox({'titleShow':false,'padding':0,'margin':0,'centerOnScroll':true,'overlayColor':'#000','overlayOpacity':'0.65'});
	$('.inline').fancybox({'titleShow':false,'padding':0,'margin':0,'centerOnScroll':true,'overlayColor':'#000','overlayOpacity':'0.65'});
	$('.frame').fancybox({'width':484,'height':620,'autoScale':false,'type':'iframe','titleShow':false,'padding':0,'margin':0,'centerOnScroll':true,'overlayColor':'#000','overlayOpacity':'0.65'});
	//print my modal content 
	$('.printme').click(function() {
	    $('#fancybox-print').css({'display':'block'});
	});
	$('.zoom, .inline, .frame').click(function() {
	    $('#fancybox-print').css({'display':'none'});
	});
	//form thingie
	$('.reservations #styleme').jqTransform();    
	

/* Detekcija browsera ******************************************************************************************************************/ 
    if($.browser.safari || $.browser.chrome){
		$('body').addClass('webkit');
	} else if ($.browser.mozilla ){
		$('body').addClass('ff');
	} else if ($.browser.msie){
		$('body').addClass('msie');
		if ($.browser.version == 7) { ieDropCap(); }
	 	if ($.browser.version.substr(0,1)<7) { $('img[src$=".png"], #foot a').addClass('png'); ieDropCap(); }
	} else if ($.browser.opera ){
		$('body').addClass('opera');
	}
});

function ieDropCap() {
    var first_paragraph = $('#hello p.first')[0];
    if (!first_paragraph) return false;
    var node = first_paragraph;
    while (node.childNodes.length) { node = node.firstChild; }
    var text = node.nodeValue;
    var first_letter = text.substr(0,1);
    var match = /[a-zA-Z]/.test(first_letter);
    if ( match ) {
        node.nodeValue = text.slice(1);
        first_letter.toLowerCase();
        $('<span id="iedropcap"></span>').text("" + first_letter + "").prependTo(first_paragraph);
    }
}
