/* Images Preloader */
var opened = false;
var windowName = null;

progressB = new Image();
progressB.src = "/public/images/new/progress-bar.gif";

copyB = new Image();
copyB.src= "/public/images/new/copy.png";




/* ZeroClipboard */
            $(document).ready(function(){
			$(".jsdropdown-menu-button-dropdown").html("");
                $('.coupon').each(function(){
                    var coupon = this;
                    var clip = new ZeroClipboard.Client();
                    var copied = false;
                    clip.setHandCursor( true );
                    clip.setText($(coupon).find('a').text());
                    //clip.glue( $(coupon).attr('id'), $(coupon).parent().attr('id') );
                    clip.glue( $(coupon).attr('id') );
                    clip.addEventListener( 'complete', function(client, text) {
                        $(coupon).parent().find('.message').text('Copied!');
                        copied = true;
                        cid = $(coupon).find('a').attr('id');
                        
                     
     
//Start writing code here     
     
         
//window.open($(coupon).find('a').attr('href'),cid);

	cid=window.open($(coupon).find('a').attr('href'),cid);        

                    
           
   
     
     
     
     
//END writing code here                         
                    
                    
                    });
                    clip.addEventListener( 'mouseOver', function(client, text) {
                        $(coupon).parent().find('.message').text('Click to copy');
                    });
                    clip.addEventListener( 'mouseOut', function(client, text) {
                        if( !copied )
                            $(coupon).parent().find('.message').text('');
                        else
                            $(coupon).parent().find('.message').text('Copied!');
                    });
                });
            });



















/* Featured */

function CWScroller(ulId, speed) {

	this.container = document.getElementById(ulId);
	this.container.Scroller = this;
	this.speed = speed;

	this.scroll = function() {
			var c = this.container.firstChild;
			var first = null;
			while (c) {
				if (c.tagName == 'LI') {
					first = c;
					break;
				}
				c = c.nextSibling;
			}
			var nodeSize = 78;	// Default
			var px = 0;
			nodeSize = first.clientWidth;
			if (first.style.marginLeft != '') {
				px = parseInt(first.style.marginLeft);
			}
			first.style.marginLeft = ( px - 1 ) + 'px';
			if ( parseInt(first.style.marginLeft) <= -(nodeSize) ) {
				first.style.marginLeft = '0px';
				this.container.removeChild(first);
				this.container.appendChild(first);
			}
		setTimeout('document.getElementById(\'' + this.container.id + '\').Scroller.scroll()', this.speed);	
	}

	setTimeout('document.getElementById(\'' + ulId + '\').Scroller.scroll()', this.speed);

}

/* js code for logo.php view */
function externalLinks() {

if (!document.getElementsByTagName) return;

var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
var relvalue = anchor.getAttribute("rel");

if (anchor.getAttribute("href")) {
var external = /external/;
var relvalue = anchor.getAttribute("rel");
if (external.test(relvalue)) { anchor.target = "_blank"; }
}
}
}
window.onload = externalLinks;

/* custom.js */

submitSure = false;

function checkSubmit(){
	if( $(".search .couponsearch").val() == '' || $(".search .couponsearch").val() == 'Coupons for online stores')
		return false;		
	else{
		if( $(".search .couponsearch").val().length <= 2 ){
			alert("Type a longer search keyword");
			return false;
		}
		else
			return true;
	}
}	

function checkSubmit2(){
	if( $(".search2.couponsearch").val() == '' || $(".search2 .couponsearch").val() == 'Coupons for online stores')
		return false;		
	else{
		if( $(".search2 .couponsearch").val().length <= 2 ){
			alert("Type a longer search keyword");
			return false;
		}
		else
			return true;
	}
}	

/* This code for contact_view.php view, and it validates name, email and comment */
function submit_contact(){
		
		var name = $("#name").val();
		var email = $("#email").val();	
		var comment = $("#comment").val();
			if(name.length < 3){
			alert("Please enter Full name");
			$("#name").focus();
			return false
		}
	
		if(email==""){
			alert("Please enter email")
			$("#email").focus();
			return false
		}
		var filter=(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/);

   if (!filter.test(email))
   {
   	 alert("Please input a valid email address!");
			$("#email").focus();
     return false;
	}
			if(comment.length < 5){
			alert("Please enter comment in detail")
			$("#comment").focus();
			return false
		}

		
			

}

function count_char()
{
	
var discount = $("#discount").val();
if (discount.length > 255) // if too long...trim it!
document.getElementById("discount").value = discount.substring(0, 255);
// otherwise, update 'characters left' counter
else
var len = 255 - discount.length;
$('#count').html(len)
}

function rate(val,coupon_id){
	var id = "vote" + coupon_id; 
	var icon = "icon" + coupon_id;
	var coupon = "coupon"+coupon_id;
	var div_id = "vote"+coupon_id;
	var txtsuc_id ="txtsuc"+coupon_id;
	$("#"+icon).animate({opacity : 0.25});
	
			$.ajax({
					url: '/home/vote/'+val+'/'+coupon_id,												
								success: function(result) 
								{
									$("#"+div_id).html(result);
									
								}
								
				});
	
									/*works fine, but removed. can be added if required.
									$("#"+div_id).animate({opacity : 0.5});
									$("#"+txtsuc_id).animate({opacity : 0.5});
									*/			
$("#"+div_id).load('/home/vote/'+val+'/'+coupon_id);
/*$("#"+div_id).animate({opacity : 0.25});*/
}

function submit_coupon(){
//	if($("#website").val() && $("#couponcode").val() && $("#discount").val()){

		var couponcode = $("#couponcode").val();
		var discount = $("#discount").val();	
		var website = $("#website").val();
			if(website==""){
			alert("Please enter website")
			$("#website").focus();
			submitSure = false;
$("#progress").css("display","none");
$("#result").html("Please make sure, all fields are filled.").css("color","red").show();
			return false
		}else{
submitSure = true;
}
		if(!isValidURL_withhttps(website)){
		alert("Enter Website in the correct format eg. http://www.xyz.com or https://www.xyz.com");
			$("#website").focus();
$("#progress").css("display","none");
			submitSure = false;
$("#result").html("Please make sure, all fields are filled.").css("color","red").show();
		return false;
	}else{
submitSure = true;
}
		if(couponcode==""){
			alert("Please enter couponcode")
			$("#couponcode").focus();
			submitSure = false;
$("#progress").css("display","none");
$("#result").html("Please make sure, all fields are filled.").css("color","red").show();
			return false
			}
			if(discount==""){
			alert("Please enter discount")
			$("#discount").focus();
			submitSure = false;
$("#progress").css("display","none");
$("#result").html("Please make sure, all fields are filled.").css("color","red").show();
			return false
			}
	if(discount.length<2 || discount.length>255){
	alert("Enter discount with min 2 and max 256 char");
	$("#discount").focus();
	submitSure = false;
$("#progress").css("display","none");
$("#result").html("Please make sure, all fields are filled.").css("color","red").show();
	return false
	
	}
progress();
submitThis();
/*		$("#coupon_msg").hide();
	$("#sc_submit").hide();
		$("#sc_submit_load").show();
			$.ajax({
					url: '/home/submitacoupon',	
					type: 'POST',
					data: 'website=' + website  + '&couponcode=' + couponcode  + '&discount=' + discount  + '&submit=ajax',
								success: function(result) {
									$("#coupon_msg").html(result).css("color","green").show();	
									$("#sc_submit_load").hide();
									$("#sc_submit").show();
									if(result=="Coupon code submitted for Approval.Thanks!"){
									$("#website").val("");
									$("#couponcode").val("");
									$("#discount").val("");
									}
								}
											 });
			
*/
//	}
	//$("#coupon_msg").html("you need to fill all values").css("color","red").show();
}

function submitThis(){
var couponcode = escape($("#couponcode").val());
var discount = escape($("#discount").val());	
var website = $("#website").val();

if(submitSure == true){
			$.ajax({
					url: '/home/submitacoupon',	
					type: 'POST',
					data: 'website=' + website  + '&couponcode=' + couponcode  + '&discount=' + discount  + '&submit=ajax',
								success: function(result) {
									$("#progress").css("display","none");
									$("#result").html(result).css("color","green").show();	
									$("#sc_submit_load").hide();
									$("#sc_submit").show();
									if(result=="Coupon code submitted for Approval.Thanks!"){
									$("#website").val("http://");
									$("#couponcode").val("");
									$("#discount").val("");
									}
								}
											 });
}else{
$("#progress").css("display","none");
$("#result").html("Please make sure, all fields are filled.").css("color","red").show();
}
}

function isValidURL(url){
	url = jQuery.trim(url.toLowerCase());
	url= url.replace('http://www.','http://');
	url= url.replace('https://www.','https://');
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
} 

function isValidURL_withhttps(url)
{
	url = jQuery.trim(url.toLowerCase());
	url= url.replace('http://www.','http://');
	url= url.replace('https://www.','https://');
    var RegExp = /^(H|h)ttp(s?)\:\/\/(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}

function progress(){
if(submitSure == true){
	$("#result").html('');
	$("#progress").css("display","block");
}
}

/* cb.js */


function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}


function createElement(element) {
	if (typeof document.createElementNS != 'undefined') {
		return document.createElementNS('http://www.w3.org/1999/xhtml', element);
	}
	if (typeof document.createElement != 'undefined') {
		return document.createElement(element);
	}
	return false;
}

function insertTop(obj) {
	d=createElement("div");
	d.className="bt"; 
    d2=createElement("div");
    d.appendChild(d2);
	obj.insertBefore(d,obj.firstChild);
}

function insertBottom(obj) {
	d=createElement("div");
	d.className="bb"; 
    d2=createElement("div");
    d.appendChild(d2);
	obj.appendChild(d);
}

function initCB()
{
	var divs = document.getElementsByTagName('div');
	var cbDivs = [];
	for (var i = 0; i < divs.length; i++) {
		if (/\bcbb\b/.test(divs[i].className))
			cbDivs[cbDivs.length] = divs[i];
	}
	var thediv, outer, i1, i2;
	for (var i = 0; i < cbDivs.length; i++) {
		thediv = cbDivs[i];
		outer = createElement('div');
		outer.className = thediv.className;
		outer.className = thediv.className.replace('cbb', 'cb');
		thediv.className = 'i3';
		thediv.parentNode.replaceChild(outer, thediv);
		i1 = createElement('div');
		i1.className = 'i1';
		outer.appendChild(i1);
		i2 = createElement('div');
		i2.className = 'i2';
		i1.appendChild(i2);
		i2.appendChild(thediv);
		insertTop(outer);
		insertBottom(outer);
	}
}

if(document.getElementById && document.createTextNode)
{
	addEvent(window, 'load', initCB);
}

/* ZeroClipboard.js */
// Simple Set Clipboard System
// Author: Joseph Huckaby

var ZeroClipboard = {
	
	version: "1.0.7",
	clients: {}, // registered upload clients on page, indexed by id
	moviePath: '/public/images/new/ZeroClipboard.swf', // URL to movie
	nextId: 1, // ID of next movie
	
	$: function(thingy) {
		// simple DOM lookup utility function
		if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
		if (!thingy.addClass) {
			// extend element with a few useful methods
			thingy.hide = function() { this.style.display = 'none'; };
			thingy.show = function() { this.style.display = ''; };
			thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
			thingy.removeClass = function(name) {
				var classes = this.className.split(/\s+/);
				var idx = -1;
				for (var k = 0; k < classes.length; k++) {
					if (classes[k] == name) { idx = k; k = classes.length; }
				}
				if (idx > -1) {
					classes.splice( idx, 1 );
					this.className = classes.join(' ');
				}
				return this;
			};
			thingy.hasClass = function(name) {
				return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
			};
		}
		return thingy;
	},
	
	setMoviePath: function(path) {
		// set path to ZeroClipboard.swf
		this.moviePath = path;
	},
	
	dispatch: function(id, eventName, args) {
		// receive event from flash movie, send to client		
		var client = this.clients[id];
		if (client) {
			client.receiveEvent(eventName, args);
		}
	},
	
	register: function(id, client) {
		// register new client to receive events
		this.clients[id] = client;
	},
	
	getDOMObjectPosition: function(obj, stopObj) {
		// get absolute coordinates for dom element
		var info = {
			left: 0, 
			top: 0, 
			width: obj.width ? obj.width : obj.offsetWidth, 
			height: obj.height ? obj.height : obj.offsetHeight
		};

		while (obj && (obj != stopObj)) {
			info.left += obj.offsetLeft;
			info.top += obj.offsetTop;
			obj = obj.offsetParent;
		}

		return info;
	},
	
	Client: function(elem) {
		// constructor for new simple upload client
		this.handlers = {};
		
		// unique ID
		this.id = ZeroClipboard.nextId++;
		this.movieId = 'ZeroClipboardMovie_' + this.id;
		
		// register client with singleton to receive flash events
		ZeroClipboard.register(this.id, this);
		
		// create movie
		if (elem) this.glue(elem);
	}
};

ZeroClipboard.Client.prototype = {
	
	id: 0, // unique ID for us
	ready: false, // whether movie is ready to receive events or not
	movie: null, // reference to movie object
	clipText: '', // text to copy to clipboard
	handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
	cssEffects: true, // enable CSS mouse effects on dom container
	handlers: null, // user event handlers
	
	glue: function(elem, appendElem, stylesToAdd) {
		// glue to DOM element
		// elem can be ID or actual DOM element object
		this.domElement = ZeroClipboard.$(elem);
		
		// float just above object, or zIndex 99 if dom element isn't set
		var zIndex = 99;
		if (this.domElement.style.zIndex) {
			zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
		}
		
		if (typeof(appendElem) == 'string') {
			appendElem = ZeroClipboard.$(appendElem);
		}
		else if (typeof(appendElem) == 'undefined') {
			appendElem = document.getElementsByTagName('body')[0];
		}
		
		// find X/Y position of domElement
		var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
		
		// create floating DIV above element
		this.div = document.createElement('div');
		var style = this.div.style;
		style.position = 'absolute';
		style.left = '' + box.left + 'px';
		style.top = '' + box.top + 'px';
		style.width = '' + box.width + 'px';
		style.height = '' + box.height + 'px';
		style.zIndex = zIndex;
		
		if (typeof(stylesToAdd) == 'object') {
			for (addedStyle in stylesToAdd) {
				style[addedStyle] = stylesToAdd[addedStyle];
			}
		}
		
		// style.backgroundColor = '#f00'; // debug
		
		appendElem.appendChild(this.div);
		
		this.div.innerHTML = this.getHTML( box.width, box.height );
	},
	
	getHTML: function(width, height) {
		// return HTML for movie
		var html = '';
		var flashvars = 'id=' + this.id + 
			'&width=' + width + 
			'&height=' + height;
			
		if (navigator.userAgent.match(/MSIE/)) {
			// IE gets an OBJECT tag
			var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
			html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
		}
		else {
			// all other browsers get an EMBED tag
			html += '<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
		}
		return html;
	},
	
	hide: function() {
		// temporarily hide floater offscreen
		if (this.div) {
			this.div.style.left = '-2000px';
		}
	},
	
	show: function() {
		// show ourselves after a call to hide()
		this.reposition();
	},
	
	destroy: function() {
		// destroy control and floater
		if (this.domElement && this.div) {
			this.hide();
			this.div.innerHTML = '';
			
			var body = document.getElementsByTagName('body')[0];
			try { body.removeChild( this.div ); } catch(e) {;}
			
			this.domElement = null;
			this.div = null;
		}
	},
	
	reposition: function(elem) {
		// reposition our floating div, optionally to new container
		// warning: container CANNOT change size, only position
		if (elem) {
			this.domElement = ZeroClipboard.$(elem);
			if (!this.domElement) this.hide();
		}
		
		if (this.domElement && this.div) {
			var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
			var style = this.div.style;
			style.left = '' + box.left + 'px';
			style.top = '' + box.top + 'px';
		}
	},
	
	setText: function(newText) {
		// set text to be copied to clipboard
		this.clipText = newText;
		if (this.ready) this.movie.setText(newText);
	},
	
	addEventListener: function(eventName, func) {
		// add user event listener for event
		// event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
		eventName = eventName.toString().toLowerCase().replace(/^on/, '');
		if (!this.handlers[eventName]) this.handlers[eventName] = [];
		this.handlers[eventName].push(func);
	},
	
	setHandCursor: function(enabled) {
		// enable hand cursor (true), or default arrow cursor (false)
		this.handCursorEnabled = enabled;
		if (this.ready) this.movie.setHandCursor(enabled);
	},
	
	setCSSEffects: function(enabled) {
		// enable or disable CSS effects on DOM container
		this.cssEffects = !!enabled;
	},
	
	receiveEvent: function(eventName, args) {
		// receive event from flash
		eventName = eventName.toString().toLowerCase().replace(/^on/, '');
				
		// special behavior for certain events
		switch (eventName) {
			case 'load':
				// movie claims it is ready, but in IE this isn't always the case...
				// bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
				this.movie = document.getElementById(this.movieId);
				if (!this.movie) {
					var self = this;
					setTimeout( function() { self.receiveEvent('load', null); }, 1 );
					return;
				}
				
				// firefox on pc needs a "kick" in order to set these in certain cases
				if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
					var self = this;
					setTimeout( function() { self.receiveEvent('load', null); }, 100 );
					this.ready = true;
					return;
				}
				
				this.ready = true;
				this.movie.setText( this.clipText );
				this.movie.setHandCursor( this.handCursorEnabled );
				break;
			
			case 'mouseover':
				if (this.domElement && this.cssEffects) {
					this.domElement.addClass('hover');
					if (this.recoverActive) this.domElement.addClass('active');
				}
				break;
			
			case 'mouseout':
				if (this.domElement && this.cssEffects) {
					this.recoverActive = false;
					if (this.domElement.hasClass('active')) {
						this.domElement.removeClass('active');
						this.recoverActive = true;
					}
					this.domElement.removeClass('hover');
				}
				break;
			
			case 'mousedown':
				if (this.domElement && this.cssEffects) {
					this.domElement.addClass('active');
				}
				break;
			
			case 'mouseup':
				if (this.domElement && this.cssEffects) {
					this.domElement.removeClass('active');
					this.recoverActive = false;
				}
				break;
		} // switch eventName
		
		if (this.handlers[eventName]) {
			for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
				var func = this.handlers[eventName][idx];
			
				if (typeof(func) == 'function') {
					// actual function reference
					func(this, args);
				}
				else if ((typeof(func) == 'object') && (func.length == 2)) {
					// PHP style object + method, i.e. [myObject, 'myMethod']
					func[0][ func[1] ](this, args);
				}
				else if (typeof(func) == 'string') {
					// name of function
					window[func](this, args);
				}
			} // foreach event handler defined
		} // user defined handler for event
	}
	
};

/* thickbox.js */

/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
		  
var tb_pathToImage = "/public/images/new/progress-bar.gif";

/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call tb_init
$(document).ready(function(){   
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
});

//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	tb_show(t,a,g);
	this.blur();
	return false;
	});
}

function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link

	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   
	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
				
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_FoundURL = false;
			if(imageGroup){
				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						if (!(TB_TempArray[TB_Counter].href == url)) {						
							if (TB_FoundURL) {
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
							} else {
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
							}
						} else {
							TB_FoundURL = true;
							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			$("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div>"); 		
			
			$("#TB_closeWindowButton").click(tb_remove);
			
			if (!(TB_PrevHTML === "")) {
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;	
				}
				$("#TB_prev").click(goPrev);
			}
			
			if (!(TB_NextHTML === "")) {		
				function goNext(){
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
					return false;	
				}
				$("#TB_next").click(goNext);
				
			}

			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			tb_position();
			$("#TB_load").remove();
			$("#TB_ImageOff").click(tb_remove);
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
			};
			
			imgPreloader.src = url;
		}else{//code to show html
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );

			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					$("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					}else{//iframe modal
					$("#TB_overlay").unbind();
						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
			}else{// not an iframe, ajax
					if($("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>Close</a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{//ajax modal
						$("#TB_overlay").unbind();
						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent")[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle").html(caption);
					}
			}
					
			$("#TB_closeWindowButton").click(tb_remove);
			
				if(url.indexOf('TB_inline') != -1){	
					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
					$("#TB_window").unload(function () {
						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					$("#TB_load").remove();
					$("#TB_window").css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if($.browser.safari){//safari needs help because it will not fire iframe onload
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});
					}
				}else{
					$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						$("#TB_load").remove();
						tb_init("#TB_ajaxContent a.thickbox");
						$("#TB_window").css({display:"block"});
					});
				}
			
		}

		if(!params['modal']){
			document.onkeyup = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		}
		
	} catch(e) {
		//nothing here
	}
}

//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

function tb_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_position() {
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}


var elm;
jQuery(document).ready(function(){
	jQuery("#bInput").val('');
	jQuery(document).mouseover(function(e){mouseEventHandler(e)});
	function mouseEventHandler(mEvent)
	{ elm = mEvent.srcElement ? mEvent.srcElement : mEvent.target ? mEvent.target : null; }
	
	jQuery("#toggleB1").hover(function(){document.getElementById("yui-gen01").className = 'yui-button yui-push-button yui-button-hover yui-push-button-hover'},function(){document.getElementById("yui-gen01").className = 'yui-button yui-push-button'});
	
/*	jQuery("#search1").click(function(){
	jQuery("#search1").hide();
	jQuery("#search-box").show();
	jQuery("#search-box input").focus();
	jQuery("#yui-gen0-button").click();
	jQuery('#bContainer').show();
	jQuery("#yui-gen01").hide();
	});
	
	jQuery("#yui-gen0-button1").click(function(){
	jQuery("#search1").hide();
	jQuery("#search-box").show();
	jQuery("#search-box input").focus();
	jQuery("#yui-gen0-button").click();
	jQuery('#bContainer').show();
	jQuery("#yui-gen01").hide();
	});

	jQuery("#bInput").blur(function(){
		try
		{
			if(elm.parentNode.parentNode.parentNode.parentNode.id == 'bContainer' || elm.className == 'yui-ac-content')
			{  }
			else
			{
				jQuery(this).val('');
				jQuery("#search-box").hide();
				jQuery('#bContainer').hide();	
				jQuery("#search1").show();
				jQuery("#yui-gen01").show();
			}
		}
		catch(e)
		{		
				jQuery(this).val('');
				jQuery("#search-box").hide();
				jQuery('#bContainer').hide();	
				jQuery("#search1").show();
				jQuery("#yui-gen01").show();
		}
	});

*/

jQuery("#search1").click(function(){
	jQuery("#search1").hide();
	jQuery("#search-box").show();
	jQuery("#search-box input").focus();
	jQuery("#yui-gen0-button").click();
	jQuery('#bContainer').show();
	jQuery("#yui-gen01").hide();
	});
	
	jQuery("#yui-gen0-button1").click(function(){
	jQuery("#search1").hide();
	jQuery("#search-box").show();
	jQuery("#search-box input").focus();
	jQuery("#yui-gen0-button").click();
	jQuery('#bContainer').show();
	jQuery("#yui-gen01").hide();
	});

	jQuery("#bInput").blur(function(){
		try
		{
			if(elm.parentNode.parentNode.parentNode.parentNode.id == 'bContainer' || elm.className == 'yui-ac-content')
			{ /*Do nothing.*/ }
			else
			{
				jQuery(this).val('');
				jQuery("#search-box").hide();
				jQuery('#bContainer').hide();	
				jQuery("#search1").show();
				jQuery("#yui-gen01").show();
			}
		}
		catch(e)
		{		/*Try/Catch is not necessary, but just to be safe!*/
				jQuery(this).val('');
				jQuery("#search-box").hide();
				jQuery('#bContainer').hide();	
				jQuery("#search1").show();
				jQuery("#yui-gen01").show();
		}
	});
	
	
/*





jQuery("#search1").click(function(){
	jQuery("#search1,#comLabel").hide();
	jQuery("#search-box").show();
	jQuery("#search-box input").focus();
	jQuery("#yui-gen0-button").click();
	jQuery('#bContainer').show();
	jQuery("#yui-gen01").hide();
	});
	
	jQuery("#yui-gen0-button1").click(function(){
	jQuery("#search1,#comLabel").hide();
	jQuery("#search-box").show();
	jQuery("#search-box input").focus();
	jQuery("#yui-gen0-button").click();
	jQuery('#bContainer').show();
	jQuery("#yui-gen01").hide();
	});

	jQuery("#bInput").blur(function(){
		try
		{
			if(elm.parentNode.parentNode.parentNode.parentNode.id == 'bContainer' || elm.className == 'yui-ac-content')
			{  }
			else
			{
				jQuery(this).val('');
				jQuery("#search-box").hide();
				jQuery('#bContainer').hide();	
				jQuery("#search1,#comLabel").show();
				jQuery("#yui-gen01").show();
			}
		}
		catch(e)
		{		
				jQuery(this).val('');
				jQuery("#search-box").hide();
				jQuery('#bContainer').hide();	
				jQuery("#search1,#comLabel").show();
				jQuery("#yui-gen01").show();
		}
	});

*/



});

			 //CWScroller('scroller-2', 30, 'horizontal'); 




/*turn off spell check*/
/*JQuery $('.textarea_className').attr('spellcheck',false);*/
jQuery(".couponsearch").attr('spellcheck',false);
jQuery(".yui-ac-input").attr('spellcheck',false);